Make sure you have a corresponding id_rsa.pub
or id_dsa.pub
in your ~/.ssh
directory.
When I had an id_rsa
but not a corresponding id_rsa.pub
, Mac OS X kept popping up the dialog and remember passowrd in my keychain did nothing.
cd ~/.ssh
ssh-keygen -y -f id_rsa > id_rsa.pub
generated the appropriate public key file for me.
If you already had your public file there (rename it to another name) and generate the public key again using the above command, you'll notice that the generated and the old one are not equal. Somehow the older versions of Mac OS X generated a public key that Lion does not like anymore, generating it again fixes that.
For the curious, the key is exactly the same, the part that changes is that there is no "comments" section after the key on the file any longer.
There is a lot of conflicting information I've read whenever I look up information on using ssh-agent
(passphrase saving/reusing process) under Mac OS X. Most resources seem to suggest that simply issuing ssh-add -K
will let you store your passphrase, and will automatically configure OS X to launch ssh-agent
automatically and load your stored passphrase.
Note: Running ssh-add -K
will only work if you have your private key file in one of the common locations, those locations being limited to: ~/.ssh/id_rsa
, ~/.ssh/id_dsa
, ~/.ssh/identity
. If the file is located anywhere else you should specify that path after the -K in the command above.
The reason you are getting the key file passphrase dialog when connecting to the second (key-less) server is likely because the default configuration of SSH servers is to use public key authentication first, and 'keyboard interactive' authentication second.
Because you have a public key with a standard name/location (~/.ssh/id_rsa
), your OpenSSH client helpfully submits the private key in order to allow the server to match it against an allowed authorized_keys
file.
There are a small handful of ways to prevent this, the easiest two being to pass a flag on the command line, or add it as a permanent configuration item in your ~/.ssh/config
file.
When connecting to the secondary/key-less server, you can add -o "PubkeyAuthentication=no" when connecting. Something like ssh -o "PubkeyAuthentication=no" me@devserver2
.
Open up ~/.ssh/config
in your favorite text editor, create it first if you must, and enter the following:
Host devserver2
User me
PubkeyAuthentication no
Now, if you simply type ssh devserver2
the username and pubkey configuration will be read in and used, and you should be prompted for your password and nothing else.
(Note: Replace devserver2 with the actual hostname of the server. Alternatively, pick a nice hostname, such as devserver2, and add a property between User and PubkeyAuthentication called 'Hostname' and put the name or IP address of the server there. Afterwards, you actually can simply type 'ssh devserver2' and all the configuration properties will work their respective magic.)
Best Answer
I guess you are using anyconnect to connect to the Cisco VPN server. AnyConnect can also be used from Terminal. This works on macOS Sierra and AnyConnect 3.1.14018. Create a bash script with the following command:
And put the login details in the file .credentials with the following three lines:
Don't forget to put reasonable permissions on the files.