Ubuntu – How to permanently save a password-protected SSH key

awesomegnome-classicsshunity

I am using Awesome Window Manager

How can I permanently add private keys with password?

Inspired by the answer here I have added the private keys in ~/.ssh/config

Contents of ~/.ssh/config:

IdentityFile 'private key full path'

Permissions of ~/.ssh/config: 0700

But it doesn't work for me.

If I manually add the key in every session, it works but I'm looking for a more elegant way (not in .bashrc)

EDIT:

  • Using Gnome classic (no effects) version.

After adding the SSH key with ssh-copy-if to the remote host, I get the following prompt in terminal (GNOME Terminal 3.0.1) when I'm logging in:

ssh -i .ssh/Password-Protected-Key user@host
Enter passphrase for key '.ssh/Password-Protected-Key':
  • Using Awesome window manager v3.4.10.
    I had already gnome-keyring-dameon so I killed the other pid and run gnome-keyring-daemon --start | grep SOCK (I also added it in .profile) the (grep) output:

SSH_AUTH_SOCK=/tmp/keyring-2LXXXX/ssh

I followed the exact same steps and likewise I haven't got any GUI ssh-add dialog.

EDIT 2:

I created a new password protected key from Ubuntu 11.10 virtual machine on unity and I still can't get any password prompt.

EDIT 3:
It seems that this cannot work in Awesome window manager 🙁 and possibly other..

Best Answer

If you are using Unity, or a session manager that starts gnome-keyring-daemon, you can simply use Seahorse (Passwords and Keys) to establish a key, define what it is for, set a passphrase, and distribute its public key to the computer you are going to use with ssh. No terminal commands are necessary.

You create the password by:

  1. selecting File->New and select Secure Shell Key. Press Continue.

  2. Type in a descriptive name, and select Create and set up.

  3. You will be prompted to enter a keyphrase twice (the second time to check that you didn't mis-enter it the first time.

  4. Enter the computer to which the public key should be used and the user name on that computer for which you will be using the key. The public key will be copied to that other computer, prompting for your password on that computer if necessary.

Now the My Personal Keys tab will display the key.

Assuming gnome-keyring-daemon was started properly when you logged into Lightdm, and again by your session manager, when you first use the key with ssh you will be prompted for the keyphrase. In this dialog box you can provide the keyphrase, select the Details control and ask that the keyring be unlocked whenever you are logged in--automatically providing this key. Press OK

You may not be prompted in this way if there is another key available for logging into the remote computer.

After this has been accomplished the first Seahorse tab Passwords will list an "Unlock password entry" for the key name. Click on the triangle before "Passwords: Login" to see it.