Re: HOWTO: SSH & Public Keys
Quote:
Originally Posted by Beernut
Next we need to copy the public key to the server.
Code:
username@ubuntu:~$ cd .ssh/
This moves you into .ssh directory where the keys were saved. Now to copy the public key to the server.
The "scp" command allows files to be copied to/from a remote server using the SSH protocol to establish a secure connection and to encrypt all data passing between the client and the server.
Now that we copied the public key to the server we have to install the key in the proper directory. To do this login to the server using ssh and your usual password. We still aren't using public key authentication yet but we are close. Once logged into the server issue the following command in the terminal. Note you don't need to be logged in as root just login with your normal user account.
Code:
username@server:~$ cd .ssh
serverusername@server:~$ touch authorized_keys2
serverusername@server:~$ chmod 600 authorized_keys2
serverusername@server:~$ cat ../id_dsa.pub >> authorized_keys2
serverusername@server:~$ rm ../id_dsa.pub
Ok so here we set the file permissions to 600 which is gives only the owner read and write access. Then we added the key to the file called authorized_keys2. Note it's important to use the >> because that adds the key to the file without any line breaks. Then finally we removed the key id_dsa.pub from the server. Now if you logout and log back in you should see that you are using the key authentication as shown below.
Nice howto :) I'm not sure if you're aware if it, but the above can essentially be replaced with the "ssh-copy-id" command. As far as I'm aware, its only a debian thing. The only real difference to the above is that it copies your key to a file called "authorized_keys" instead of "authorized_keys2", but it still works the same.
I'm glad you said that the user must enter a password. IMO, if you don't passphrase your key, you're asking for trouble ;)
You might also like to add something about ssh-add as it saves you from entering your passphrase everywhere.
Re: HOWTO: SSH & Public Keys
Thanks for the howto! But how do I disable regular password authentication now that this is in place?
Re: HOWTO: SSH & Public Keys
Quote:
Originally Posted by Heliode
Thanks for the howto! But how do I disable regular password authentication now that this is in place?
I forgot about this part I'll add it to the HOWTO above. You need to edit the following file on the server. /etc/ssh/ssh_config now there are a few ways to do this like below.
Code:
sudo vim /etc/ssh/ssh_config
sudo gedit /etc/ssh/ssh_config (Enter this one only if you are on the server.)
If you know how to use the VI editor you edit the file from terminal on a remote host. I am not that good with VI so I won't even attempt to tell you how to do it that way. ;-)
When you open the file all you have to do is change the following line to no.
Code:
# PasswordAuthentication no
That should do it for you.
Re: HOWTO: SSH & Public Keys
Quote:
Originally Posted by airhead
Nice howto :) I'm not sure if you're aware if it, but the above can essentially be replaced with the "ssh-copy-id" command. As far as I'm aware, its only a debian thing. The only real difference to the above is that it copies your key to a file called "authorized_keys" instead of "authorized_keys2", but it still works the same.
I'm glad you said that the user must enter a password. IMO, if you don't passphrase your key, you're asking for trouble ;)
You might also like to add something about ssh-add as it saves you from entering your passphrase everywhere.
Thanks. I just found the "ssh-copy-id" command but wasn't sure if it would work the same. The file is named "authorized_key2" so that if you want to have seperate keys for Protocol 1 & Protocol 2 versions of ssh. I am going to try it on my Suse box to see if it is just a Debian thing or not.
I hate blank passwords or passphrases. Why go through the trouble of securing you server and then leave that out?
Thanks for the hint on ssh-add command I'll have to look into it. Does that just remember your password for the current session?
Re: HOWTO: SSH & Public Keys
Quote:
Originally Posted by Beernut
Thanks for the hint on ssh-add command I'll have to look into it. Does that just remember your password for the current session?
Thats correct.
When turning off password auth, I found that my debian testing version of sshd already had "PasswordAuthentication no". To really turn it off, you need to set "UsePAM no" (as sshd uses pam instead of doing the authentication itself).
Re: HOWTO: SSH & Public Keys
Hey, i'm probably doing something wrong here,but i've set password authentication to 'no' on my (Gentoo) server in the /etc/ssh/ssh_config file, but I can still logg in with my regular password if I just hit enter when it asks me for the passphrase for the key. any idea what might be causing this?
Re: HOWTO: SSH & Public Keys
Quote:
Originally Posted by Beernut
When you open the file all you have to do is change the following line to no.
Code:
# PasswordAuthentication no
That should do it for you.
I think you should remove that comment (#) after chaning it to "no."
EDIT: wait a sec..whay are we setting up "password authentication no" in ssh_config? Isn't it sshd_config we should be changing?
Re: HOWTO: SSH & Public Keys
OOPS Missed the comment that's the bad thing with copy and paste. As far as changing it in the sshd_config file I don't have one on my system. At least not in /etc/ssh/ which is where it should be according to the documentaion at OpenSSH.
Also I don't see the anything about the "UsePAM no" option in the manual.
Re: HOWTO: SSH & Public Keys
Great howto. Very easy to follow. I have only one question: You explained how to generate the keypair on two Ubuntu boxes, I'm curious. I run the SSHD at home on my ubuntu box but often connect from my workplace using Putty. How does one go about generating another keypair on windows with Putty?