Setting Up SSH Keys

Posted by Chief on Sep 23, 2009 in System Administration
No Comments

Question How do I configure my machine to be able to ssh into another machine without having to enter a password every time?

Answer:
Let’s first define a few things.

  • localhost – Your regular, every-day machine. This machine will be making outbound calls to other machines, and is the originator of the ssh/scp requests.
  • server – The machine to which one would want to log into via ssh, or scp files to.

First, generate the localhost’s key:
localhost$ ssh-keygen -b 4096 -t rsa
localhost$ scp ~/.ssh/id_rsa.pub server:~/.ssh/localhost.pub

We’ll go the fail-safe way, ensuring that an authorized_keys file exists, then we’ll cat the old with the new and replace the existing authorized_keys file:
server$ touch ~/.ssh/authorized_keys
server$ chmod 600 ~/.ssh/authorized_keys
server$ cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.bak
server$ cat ~/.ssh/authorized_keys.bak ~/.ssh/localhost.pub > ~/.ssh/authorized_keys

That’s all there is to it.

Question Why would you want to do that?

Answer:
Say you have a bash script that needs to copy files to another machine every time they are generated. The best way to do that is to scp them. Scp requires ssh authorization. By setting up these keys, you can allow your script to scp files securely without locking at the password prompt.

Tags: , , , ,

Copyright © 2010 cat brain.log | less All rights reserved.
Shades v1.2 theme from BuyNowShop.com.