Mon - Aug 25, 2008 : 04:48 pm
tired
Generating SSH Key Pairs
Today I needed to sync a file on two servers using ssh, and I needed to do it automatically. I knew that ssh could use key-pairs to enable a secure authentication system without requiring passwords, but I couldn't remember how to do it. I googled a bit and found this gem of a tutorial on how to do precisely what I needed: I'll post both the link and the text, just for easy future reference.
Here's the text:
To {ssh, scp} from HostA to HostB without issuing a password:
On both HostA and HostB,
mkdir ~/.ssh
chmod 0700 ~/.ssh
On HostA,
cd .ssh ssh-keygen -t rsa1 -C "Some comment"
ssh-keygen -t rsa -C "Some comment"
ssh-keygen -t dsa -C "Some comment"
Each of the 'ssh-keygen' commands will prompt you for a passphrase. Choose something easy to remember but difficult to guess. The commands will produce the files
~/.ssh/identity, ~/.ssh/identity.pub
~/.ssh/id_rsa, ~/.ssh/id_rsa.pub
~/.ssh/id_dsa, ~/.ssh/id_dsa.pub
respectively.
The "*.pub" files are your public keys. The others are your private keys - guard them carefully. If they're stolen, then your account on HostB, or any other machine where you've set up public-key authentication, is wide open to the thief.
On HostA,
scp ~/.ssh/identity.pub HostB:~/.ssh/authorized_keys
cp ~/.ssh/id_rsa.pub some_temp_file
cat ~/.ssh/id_dsa.pub >> some_temp_file
scp some_temp_file HostB:~/.ssh/authorized_keys2
On HostB,
chmod 0600 ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys2
Now you should be able to 'ssh' from HostA to HostB without a password, but 'ssh' will prompt you for a passphrase, because it needs to decrypt your private keys.
and here's the link:
http://osdir.com/ml/netbsd.help/2002-04/msg00162.html
Computers / Linux / Programming