Monday, January 27, 2014

ssh to a server without asking password

I found this is the super easy way:

Step 1: Create public and private keys using ssh-key-gen on local-host
Step 2: Copy the public key to remote-host using ssh-copy-id
ssh-copy-id user@hostname.example.comor if you want to specify the public key file
ssh-copy-id -i ~/.ssh/

What ssh-copy-id did is basically copying the content in the ~/.ssh/ to the ~/.ssh/authorized_keys in remote server. 

If you want to make the login even quicker, you can set an alias in the .bashrc, like
alias host="ssh"
Next time, you just need to type host, which will bring you directly to the host. Easy?

btw, if ssh-copy-id is not found for your system (e.g. default case in Mac OS), you can easily install it by using:
brew install ssh-copy-id

No comments:

Post a Comment