A while ago I wrote a tip that showed you how to copy your public SSH key to a remote server to allow you to login without entering a password every time. I’ve since put this into a script that I use, and today I got sick enough of copying that script onto yet another machine that I packaged it up as a gem, so now we can all use it.
It works just like the plain old ’ssh’ command, but this time you’ll never have to enter your password again:
ssh-forever username@yourserver.com
Your key will be generated (if necessary), copied to your server, and you’ll be logged in as normal.
Installation
gem sources --add http://gemcutter.org gem install ssh-forever
Example:
[matt@bowie ssh-forever (master)]$ ssh-forever mattwynne@mattwynne.net You do not appear to have a public key. I expected to find one at /Users/matt/.ssh/id_rsa.pub Would you like me to generate one? [Y/n]y Copying your public key to the remote server. Prepare to enter your password for the last time. mattwynne@mattwynne.net's password: Success. From now on you can just use plain old 'ssh'. Logging you in... Linux broncos 2.6.29-xeon-aufs2.29-ipv6-qos-grsec #1 SMP Thu Jul 9 16:42:58 PDT 2009 x86_64 _ | |__ _ _ ___ _ _ __ ___ ___ | '_ \ '_/ _ \ ' \/ _/ _ (_-< |_.__/_| \___/_||_\__\___/__/ Welcome to broncos.dreamhost.com Any malicious and/or unauthorized activity is strictly forbidden. All activity may be logged by DreamHost Web Hosting. Last login: Sat Aug 15 17:24:17 2009 [broncos]$
Why?
Because I can never remember how to do it by hand. Now I don’t have to, and nor do you.


Silvan
| 16-Aug-09 at 2:22 pm | Permalink
I always use: ssh-keygen -t rsa && ssh-copy-id user@domain But nodoubt, ssh-forever is a much cooler name!
Matt
| 16-Aug-09 at 6:39 pm | Permalink
Ha! Yes I did actually discover ssh-copy-id as I was polishing off the gem. Pretty nice, and it has the added flexibility of being able to use a custom file for your public key, but it’s not installed on Mac OS X by default, and hopefully ssh-forever is pretty easy to install - that was the idea.
Double Shot #519 « A Fresh Cup | 17-Aug-09 at 11:14 am | Permalink
[...] Pain-free and fun password-less SSH with ssh-forever – Just like the title says. [...]
Rex Roof
| 17-Aug-09 at 4:05 pm | Permalink
How do you handle an already existing authorized_keys file on the server? do you just write over it?
Matt
| 17-Aug-09 at 8:12 pm | Permalink
Hi Rex,
Fear not. It uses << to append your public key to the existing authorized_keys file on the server, same as if you’d copied and pasted it in by hand. So nothing will get over-written, no.
Jonas Grimfelt
| 17-Aug-09 at 9:52 pm | Permalink
I’m not using port 22 on my server (security reasons), and the -p PORT don’t seem to work for me with the ssh-forever. How do I do that?
Matt
| 17-Aug-09 at 9:57 pm | Permalink
Hi Jonas,
The code is open source and you should be able to hack it pretty easily to do what you want. If you fork the code on github and submit a patch I can build it into the main gem.
Pain-free and fun password-less SSH with… « bst On Web Dev | 18-Aug-09 at 1:17 am | Permalink
[...] 12:16 am on August 18, 2009 Permalink | Reply http://blog.mattwynne.net/2009/08/16/pain-free-and-fun-password-less-ssh-with-ssh-forever/ – Pain-free and fun password-less SSH with ssh-forever [...]
Ben Mabey
| 18-Aug-09 at 6:09 am | Permalink
Very handy. Thanks for sharing.
Matt
| 05-Sep-09 at 5:52 pm | Permalink
Thanks for doing that Jonas!
Folks, version 0.2.1 of ssh-forever now supports -p PORT