If you have to do a lot of ssh, scp for a remote server you might find it annoying that it asks for password. It asks for password in a separate tty so you can not even automate it. If typing password bothers you too much you can change it so it wont ask you again. We are not turning of any authentication or disabling anything. We’ll just use a key file thats it.
Say your server name is server. And you are in a linux box. Follow these steps.
- In the terminal run
ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/shiplu/.ssh/id_rsa):
- In the ‘Enter file in which to save the key’ prompt type a file name where you want to store the key. Dont just press enter which will overwrite the current key file. Suppose you enter my-key.
- It’ll ask for a passphrase twice. Dont put anything. Just press enter twice to make it password less.
- You’ll see two files my-key and my-key.pub is created. Now copy the my-key.pub to your server by scp/rcp/rsync. This will be the last time you are copying something with password!
- Login to the server. Remember the login username. On the serverrun this command.
cat /path/to/my-key.pub >> ~/.ssh/authorized_keys
This command will add the public key in .ssh/authorized_keys in login users home directory (~).
- Now from the workstationyou can login without password by
ssh -i /path/to/my-key -l LOGIN_USERNAME server
- For later convenience, put this in your
~/.bashrc
filealias server_ssh='ssh -i /path/to/my-key -l LOGIN_USERNAME' alias server_scp='scp -i /path/to/my-key -l LOGIN_USERNAME'
Now you can login easily by
server_ssh server