Search This Blog

Wednesday, April 02, 2008

ssh to remote server without password

  1. install openssh in both local and remote machine;
  2. run ssh-keygen in the local machine,you'll get id_rsa and id_rsa.pub;
  3. well,the file id_rsa stors your private key,you must keep it secret;
  4. while id_rsa.pub is the public key,just keep it from writing by others.
  5. deliver id_rsa.pub to the remote server you want to login without password by whatever ways,e.g. scp .ssh/id_rsa.pub user@server:.ssh/ of course you will be prompted for password this time,make sure there is a .ssh directory in the remote server and it's mode is 700
  6. cat .ssh/id_rsa.pub >> .ssh/authorized_keys (run in remote server)
  7. chmod 644 .ssh/id_rsa.pub .ssh/authorized_keys (also in remote server)
  8. now have a try.
note:when you run ssh server without a username,ssh asumes you want to login to remote server with the same user as the local one.
note2:
if you put your non-root user's public key to /root/.ssh of the remote server,then you can login to remote server as root directory,so either avoid this situation or protect the password of your local account.