SSH login without specifying a password
You sometimes want to have a shell script automatically log on to another server, e.g. for transferring files. Sharing a key is the way to go.
First, you have to create a key”
cd ~
ssh-keygen -t rsa
ssh-keygen -t rsa
I usually answer with the default value (by typing
Send this key to the computers you want to connect to without a password (in this example, you’ll want to connect to the remote computer as the user ‘root’):
export computer=server1.example.com
cat ~/.ssh/id_rsa.pub | ssh $computer ‘cat >> /root/.ssh/authorized_keys’
cat ~/.ssh/id_rsa.pub | ssh $computer ‘cat >> /root/.ssh/authorized_keys’
Verify you can ssh without entering a password:
ssh $computer
Add new comment