Sunday, June 22, 2014

Passwordless SSH and SCP to Unix Server

In this article we will see how we can do SCP and SSH to remote server without giving any password. 
This helps while we are writing a bash script for doing ssh and scp.

Run this command on LocalMachine
$ ssh-keygen -t dsa

Add following lines to your .bash_profile on your LocalMachine:
# So that ssh will work, take care with X logins - see .xsession
[[ -z $SSH_AGENT_PID && -z $DISPLAY ]] &&
exec -l ssh-agent $SHELL -c "bash --login"

Run these command on LocalMachine
$ ssh-copy-id RemoteServer
$ scp ~/.ssh/id_dsa.pub RemoteServer:.ssh/id_dsa.pub.LocalMachine

Run these command on RemoteServer
$ cat ~/.ssh/id_dsa.pub.LocalMachine >> ~/.ssh/authorized_keys
$ rm ~/.ssh/id_dsa.pub.LocalMachine
$ chmod 600 ~/.ssh/authorized_keys
$ chmod 700 ~/.ssh

After executing the above commands we will be able to SCP or SSH to RemoteServer from LocalMachine.

No comments:

Post a Comment

Password Protected Solr Admin Page

As we all know Solr Admin Page is not password protected and anyone can get into Solr Admin Page. However this article will ...