cat brain.log | less

Getting it down on `paper`

Setting Up SSH Keys

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.

 

Comments

No comments so far.

(comments are closed)