Tip Details Add a Related Tip

Rate as: Positive Negative

ssh and scp without passwords

If you are a frequent user of the ssh or scp command, you are probably pretty tired of having to enter your password for the remote machine every time you execute one of these commands. Well, if you are certain that your local machine is secure, then it turns out that it's pretty easy to set up a trust relationship between your machine and the remote machine using private certificates.

The example I am going to show is performed on a Mac. I assume that for a Linux/Unix machine, the procedure is identical, although the file names may differ slightly. If you are on a PC, I assume there is some way to generate keys and that once they are generated, the process is the same. But I don't know the way that keys are created on a PC.

That said, here we go:

1 - Open a terminal window. If you don't know how to open a terminal window, you should probably stop right now since these trust relationship between machines is only really of use for people who routinely use the terminal.

2 - Enter the following command at the command prompt:

ssh-keygen

You'll be prompted to answer several questions as part of the key generation. For all of them, just accept the default value by hitting the Enter key at each of the prompts.

3 - Once the command executes, you should be able to go to the .ssh directory in your root directory (cd ~/.ssh) and you should then see files called: id_rsa and id_rsa.pub.

4 - Copy the id_rsa.pub file to your remote machine (scp id_rsa.pub yourUser@yourMachine, where you put in the correct value for your user and machine).

5 - ssh to your remote machine.

6 - In your root directory, do an ls -a to see if you have an existing directory called .ssh.

7 - If you do not have an existing directory called .ssh, create one (mkdir .ssh) and change the permissions to be 700 (chmod 700 .ssh).

8 - Change into the .ssh directory.

9 - If you do not have an existing file called authorized_keys, copy your id_rsa.pub file into this directory with that name (mv ../id_rsa.pub authorized_keys).

10 - If you do have an existing file called authorized_keys, you'll want to append the contents of the id_rsa.pub to the existing authorized_keys file (cat ../id_rsa.pub >> authorized_keys).

11 - Make sure that the permissions of the authorized_keys are 644 (chmod 644 authorized_keys).

Once you complete this quick process, you'll be able to use the ssh and scp commands to your remote server without needing to enter your password.
Rating: 100% positive, 4 total Votes
Categories: shell Mac linux UNIX
Added: on Dec 21, 2007 at 2:51 pm
Added By: an anonymous user

Comments on this Tip

Add a Comment
Awesome tip, I've been wanting to be able to do this for a long time.
– Added by an anonymous user on Jun 20, 2008 at 9:19 am
Your Comment:
(how to format)
Rate This Tip:

Verify Humanity:
Sorry, we know it's annoying, but please enter the characters shown in the image to the left so that we know you're an actual person and not an evil spammer. Thanks.
       

Related Tips

Update your shell prompt

Categories: UNIX Mac linux shell
no ratings, 0 comments
– Tip added by an anonymous user on Jun 04, 2007 at 9:15 pm

Running X11 programs from the terminal

no ratings, 0 comments
– Tip added by an anonymous user on Jan 28, 2008 at 8:04 am

Changing an already running job to execute in the background

Categories: linux UNIX Mac
no ratings, 0 comments
– Tip added by an anonymous user on Aug 06, 2007 at 11:57 am

Color coding the ls command in Fedora

100% positive, 0 comments
– Tip added by an anonymous user on Apr 25, 2008 at 8:27 am

iTerm for the Mac

Categories: Computers Mac UNIX
66% positive, 1 comment - last added on Mar 06, 2007 at 4:29 pm
– Tip added by rlansky on Mar 03, 2007 at 7:02 am

Software Development Automation with Scripting Languages

Categories: linux unix scripting
no ratings, 0 comments
– Tip added by an anonymous user on Jun 05, 2008 at 2:40 pm

web clip widgets

100% positive, 0 comments
– Tip added by an anonymous user on Jul 01, 2008 at 9:20 am

Remove Spotlight icon from manu bar

100% positive, 0 comments
– Tip added by an anonymous user on Jun 30, 2008 at 5:54 am

Installing PHP GD on a Leopard Mac

100% positive, 0 comments
– Tip added by an anonymous user on Jun 27, 2008 at 1:39 pm

Adding searches to the Finder sidebar

100% positive, 0 comments
– Tip added by an anonymous user on Jun 27, 2008 at 9:07 am

Speeding Office 2008 on a Mac

100% positive, 1 comment - last added on Jun 26, 2008 at 3:20 pm
– Tip added by an anonymous user on Jun 26, 2008 at 11:26 am

Quick searches in Safari

Categories: Mac safari search shortcut
100% positive, 0 comments
– Tip added by an anonymous user on Jun 25, 2008 at 9:26 am

Quickly emailing links on a Mac

Categories: Mac email shortcut
100% positive, 0 comments
– Tip added by an anonymous user on Jun 20, 2008 at 6:31 am

Printing Keynote handouts

100% positive, 0 comments
– Tip added by an anonymous user on Jun 19, 2008 at 5:48 pm

Exporting facebook events to iCal

Categories: Facebook iCal Mac calendar
no ratings, 0 comments
– Tip added by an anonymous user 8 hours, 8 minutes ago

Change the Spaces dragging delay

no ratings, 0 comments
– Tip added by an anonymous user 12 hours, 30 minutes ago

Aperture loupe style

no ratings, 0 comments
– Tip added by an anonymous user on Jul 01, 2008 at 6:34 am

Avoid messaging when apps hang on a Mac

Categories: Mac crash shortcut
no ratings, 0 comments
– Tip added by an anonymous user on Jun 30, 2008 at 3:25 pm

Watch hi-def movie trailers in Front Row

Categories: Mac movies Front Row HDTV
no ratings, 0 comments
– Tip added by an anonymous user on Jun 30, 2008 at 6:12 am

keep track of the phase of the moon

Categories: Mac astronomy moon menu bar
no ratings, 0 comments
– Tip added by an anonymous user on Jun 23, 2008 at 4:53 pm