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.
Tags: authorized_keys, automated, rsa, scp, ssh
-
tail -7 brain.log
Commonly Keyed
aspire awk bash beethovan bug cli command line compile configure creativity cron desire directory dns function git goals hwclock install java language learning linux log math mercator mysql Napoleon Hill network path php proj4 python Quotes redirect sbin stocks success sysadmin sysconfig Think and Grow Rich timezone ubuntu wkt writinghistory
- August 2010 (4)
- July 2010 (2)
- June 2010 (8)
- May 2010 (2)
- April 2010 (4)
- March 2010 (4)
- February 2010 (4)
- January 2010 (4)
- December 2009 (9)
- November 2009 (21)
- October 2009 (3)
- September 2009 (1)
- July 2009 (1)
- June 2009 (1)
- December 2008 (1)
- October 2008 (1)
Filed Under
- Gotchas (4)
- Lessons (8)
- Quotes (11)
- Reference (25)
- Scripts, Tricks and Hacks (12)
- Socratic deductions (1)
- Synopses (6)
- System Administration (11)
- Thought Fragments (6)