Yesterday, I was working on some shell script piece for my project and I came across a situation where I have to copy some files from one server to another using ‘scp’ command and also some time have to execute some command on other server. One requirement was we don’t need to pass the password of functional id inside the script.
User should be able to login to other server without password using command “ssh -l username remotehost”.
For this I used SSH public key based authentication as below:-
For this to work you need a file named id_dsa.pub in your ~/.ssh Directory. If it’s not there, simply create it with below command:
ssh-keygen -t dsa
above command will create below directory with public and private keys:
now copy id_dsa.pub file to remote server .ssh/ directory as “authorized_keys2” with whom you would like to do an automated login.
After that try below command from source server, no need for password
ssh -l username remotehost
For more details can view link