I wanted to make a shell script that connects to a hidden wireless network on my macbook pro by creating a network. However, I only want to connect to that network when I want to and to prevent airport from connecting automatically I'll have to delete the network's password from keychain.
So far I have:
networksetup -setairportnetwork en1 $ssid $networkpassword
networksetup -removepreferredwirelessnetwork en1 $ssid
Im also aware that in OSX 10.7 the security command can modify the keychain.
Anyway I would appreciate any help someone can give me. I'm also willing to use applescript or something else if it works. Thank you.
I figured it out. The command I used is:
sudo security delete-generic-password -l $ssid "/Library/Keychains/System.keychain"
sudo was needed because this keychain is located in the systems library. security also contains a lot more delete and useful commands and you can specify how you want to indicate the location in this command.
edit: I was having some trouble using this command and went back and learned I could use another command to not remember the network at all which I would have used before if I had found it. With this option you can do a wealth of things with your adapter along with the networksetup option.
Here is my final script which first runs as root. then it changes the system preferences to not remember new networks. Then it disconnects from any current networks. Then it adds the new network. Lastly, it makes the system remember new wifi networks.
sudo -i
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport prefs RememberRecentNetworks=NO
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -Z
networksetup -setairportnetwork en1 $ssid $password
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport prefs RememberRecentNetworks=YES
Related
in Windows i'm using as below.
netsh wlan connect ssid=YOUR-WIFI-SSID name=PROFILE-NAME
Need similar for the mac os.
I think it will depend on whether you have saved the WiFi password in your keychain but the basic command is networksetup as follows:
networksetup -setairportnetwork en0 YOUR_NETWORD_SSID
For more information, try:
man networksetup
"dhcp35:~ user$" has appeared in my mac terminal instead of the usual "My-MacBook-Pro:~ user$".
Is this an indication of anything malicious?
I've been messing around cliclick to automate key presses from terminal, so not sure if this has resulted from my messing or from something I might have downloaded.
dhcp is documented as part of the terminal server user guide, but I can't work out the significance.
I suspect you are connected to a DHCP server that sets the hostname along with giving an IP assignment:
https://www.rfc-editor.org/rfc/rfc2132#section-3.14
One way to stop the hostname from changing is to do the following from a Terminal window (assuming you want to name your computer donald). You may need to preface these commands with sudo:
scutil --set ComputerName donald
scutil --set HostName donald
scutil --set LocalHostName donald
I'm trying to use the bash shell to get a wifi profile for a certain network, and from that, the password
What I'm looking for is basically a mac equivalent to netsh wlan show profile name="name" key=clear, which gets exactly what I want with windows
I have looked into the airport and networksetup commands on mac, but still have yet to find something that will either show me the network profiles or, even better, what's inside.
Does anyone have any ideas or at least something to point me in the right direction?
If it's okay to use a Node.js script for this, you might have a look at wifi-password-cli which does exactly what you want:
$ wifi-password --help
Usage
$ wifi-password [network-name]
Example
$ wifi-password
unicorns
$ wifi-password foo-network
foosecretpassword
(Sample taken from the tool's documenation)
To use it, simply run (supposed that Node.js has already been installed on your system before):
$ npm install -g wifi-password-cli
The simple way is:
security find-generic-password -ga "ROUTERNAME" | grep "password:"
Add the WIFI name you are connected in the place of ROUTERNAME
Simply run the command from terminal app
security find-generic-password -wa <WIFI_NAME>
Replace <WIFI_NAME> with your Wifi Name.
A prompt will ask you for username and password.
I'm trying to mount to a webdav share over terminal on OS X. But it doesn't work very well.
mount_webdav -i "http://<ip-address>:80/Path/" "/Path/To/mntpnt/"
This is working, because it's prompting for username and password.
BUT!
mount_webdav -i "mount_webdav "http://<windomain>;<username>:<Password>#<ip-address>:80/Path/" "/Path/To/mntpnt/"
This command above don't work.
Have someone a good idea?
Is it possible to automate the -i command over a bash script?
If you store your username and password into your OS X keychain, mount_webdav should automatically pick it up.
s a sidenote, I was under the impression that it's a bad idea to call mount_webdav directly, and you should go via mount instead. But it's possible that that's only true for linux.
I am getting a error while accessing the firefox using X11Forwarding.
[root#station2 ~]# firefox
KiTTY X11 proxy: wrong authorisation protocol attemptedKiTTY X11 proxy: wrong authorisation protocol attemptedError: cannot open display: localhost:10.0
setup the following values: /etc/ssh/sshd_config
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
** Installed the package**
#yum install xorg-x11-xauth
#yum -y install xauth
[root#station2 .ssh]# echo $DISPLAY
localhost:10.0
#mkxauth -c
adding key for station2.example.com to /root/.Xauthority ... done
export XAUTHORITY=$HOME/.Xauthority
This fix worked for me
There is a hard, if not even impossible, to find (by search engine) scenario that may may cause that error message.
Preliminary note: The topic of this answer is not to discuss if it is a safety
risc or recommondable at all to use a graphical desktop as root on an remote, display-less, webserver.
Scenario:
A remote internet connected Linux server S has assigned the domain
name example.com to it's public IP4-address 192.0.2.1.
The /etc/hostname file on S contains the single line example.
The /etc/hosts
file on S contains the line 127.0.0.1 localhost example.com example.
The (remote) ssh access to S is by (sshd-) configuration (on S) forbidden
for root by the line DenyUsers root in /etc/ssh/sshd_config, but
allowed for a dummy user user1. From a client computer C a ssh
connection, using the ssh parameter -X or -Y, is established to S
as user user1.
Then, in a remote terminal on S owned by user1,
if any X11 related command is tried to be executed as root, may it be by
su, then trying to start the X11 desktop environment
or, as in the concrete case executing a script containing
#!/bin/bash
su --preserve-environment -c "xfce4-session &" root
the error message
X11 connection rejected because of wrong authentication.
is output and the start of any X11 related program fails.
The DISPLAY variable of root's environment contains
example.com:10.0
then.
One solution to the problem is, in this special case, to modify the line
127.0.0.1 localhost example.com example
in /etc/hosts to
127.0.0.1 localhost
Solution: run the application with the same user you are SSHing.
I have also encounter such errors while using X11.
The source of my problem was that i used SSH with my own username (which was not root).
Then, once logged in i tired running stuff with X11 while doing "su" or doing "sudo",
the problem with that is that the SSH session is configured with your own username - e.g: Raj, but then you switch to user root which is not part of the X11 session.
So what you should do is simply try to run the application (firefox in your case) with the same user you started the X11 session.
Hope this helps.
Talel.
I ran into this running gvim over ssh -t -Y and the solution that worked for me was:
xauth add $(xauth -f ~<logon_user>/.Xauthority list | tail -1) ; export NO_AT_BRIDGE=1 # gvim X11 fix for remote GUI failure after su
I do not know where I stumbled on this answer so I cannot give credit to the author.