linuxcrypt, linux, oss

To use public keys with and ssh server, you’ll first need to generate a public/private key pair:

$ ssh-keygen -t rsa

You can also use -t dsa for DSA Keys, or a -t rsa1 if you’re using Protocol v1. If you are then you should upgrade to v2 because I said so.

After you enter the above command, you should see something like this:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/josh/.ssh/id_rsa):

Just hit (enter), it will then ask you for a pass phrase; just hit (enter) twice: but read the security note.

This created two files: (/home/josh/.ssh/id_rsa) and (/home/josh/.ssh/id_rsa.pub) To use this key-pair on a server, try this:

$ ssh server “mkdir .ssh; chmod 0700 .ssh”
$ scp .ssh/id_rsa.pub server: .ssh/authorized_keys2

Naturally, replace “server” with “your” server :) It should ask you for your password both times. Now, just run a:

$ ssh servername

It should log you in automatically without a password, it will also use your new public key for “scp” connections as well.

If this did not work, then check the permission values on both (/home/josh/.ssh/*) and (server:/home/josh/.ssh/*). Your private key (id_rsa) should be 0600 (and only be present on your local machine), and everything else should be 0655 or better.

*Security Concerns

Some people consider using keys as a possible security issue. This is a valid concern because your private key could potentially be copied, but then again, so could a password, so just remember to keep what’s private, protected, and what’s public ..well, public.

Enjoy,
Any questions feel free to post in the comments and I will try to answer.

~j

No TweetBacks yet. (Be the first to Tweet this post)



Leave a Comment