SEARCH

BYTE SIZE TIPS / QUICK, HELPFUL TIPS

How-To Geek

Bypass SSH Logins by Adding Your Key to a Remote Server in a Single Command

If you want to setup SSH keys to allow logging in without a password, you can do so with a single command. It’s quite easy.

The first thing you’ll need to do is make sure you’ve run the keygen command to generate the keys (if you have already generated keys, skip this step).

ssh-keygen -t rsa

Then use this command to push the key to the remote server, modifying it to match your server user name and host name.

cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'

You’ll have to enter your password the first time to copy the keys. After that, you should be able to login without a password, or even use scp or rsync without entering a password. You can test with this command:

ssh user@hostname

It’s definitely a lot easier than typing in a password all the time.

Alternate Method

You can also use the ssh-copy-id command instead. For instance, after generating your keys, use this command:

ssh-copy-id -i ~/.ssh/id_rsa.pub user@hostname

Easy.

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 03/11/13

RECOMMENDED POSTS

Enter Your Email Here to Get Access for Free:

Go check your email!