Automatic SSH / SSH without password
- by Liang Li
SSH is a secure clone of RSH with RSA encryption based authentication. This
article tells you how to use ssh without
having to type in your password every time you use 'ssh'.
0. The basis of using ssh without typing your password is public key based
authentication. You need to generate a pair of public/private keys for this.
Make sure you have 'ssh-keygen' in your PATH. There are two versions of
'ssh-keygen' using SSHv1 and SSHv2 correspondingly.
1. Firstly, generate your public/private keys using ssh-keygen
type 'ssh-keygen' ( for SSHv1). This will generate 'identity' and
'identity. pub' in the .ssh directory in your home directory.
type 'ssh-keygen -t rsa' (for SSHv2). This will generate 'id_rsa' and
'id_rsa.pub' in the .ssh directory in your home directory.
Note: To simplify
the case, no 'passphrase' is used. This could be dangerous if someone else have
access to your 'identity' or 'id_rsa' file, be careful with these files (but not
those *.pub file).
2. Copy the *.pub file to the .ssh directory of the remote host you want
to logon to and rename *.pub as 'authorized_keys' or 'authorized_keys2'. Use 'scp'
for this copying:
type 'scp ~user1/.ssh/identity. pub user2@remotehost:~user2/.ssh/authorized_keys'
for SSHv1
type 'scp ~user1/.ssh/id_rsa.pub user2@remotehost:~user2/.ssh/authorized_keys2'
for SSHv2
'user1' and 'user2' can be the same or different as long as you have
access for both of them. You are basically telling the SSH daemon on the remote
machine to encrypt the connection with this public key and that this key is
"pre-authorized" using the SSH protocol given in 'authorized_keys' file. In this
way, no password is needed for SSH connection.
Note: If you have more than one host from which
you want to connect to the remote host, you need to add the content of local host's
*.pub file as one line in the 'authorised_keys' file of the remote host, i.e.
one host per line.
3. Your public key based authentication has been setup. You won't be asked
your password when ssh to the remote machine:
type 'ssh
user2@remotehost' or simply 'ssh
remotehost' (if user1=user2)
Voila ! You'll be logged in without typing in
your password.
Note: If 'ssh' between machines using different versions of
SSH, you might need to do two versions at the same time to guarantee the
success.