What is the best way of doing scp from one box to the other without prompting for password?

There are two servers:

  • Server A ( /home/oracle/export/files.txt

  • Server B ( /home/oracle/import/

If I want to transfer the files using scp from server A to server B without being prompted to enter a password

[running this from Server A, /home/oracle/export/]

scp files.txt oracle@

This would prompt me for a password upon entering the command.

I understand that a keygen is required to be generated and copied to Server A. Thus [at server A]:

ssh-keygen -t rsa

This gives me two files stored in /home/oracle/.ssh:


1. Am I supposed to copy the two files (id_rsa, id_rsa.pub) over into server B /home/oracle/.ssh ?

While doing some google search on this, some articles mentioned about appending/concatenating this to authorized_keys.

2. Am I supposed to create this file on my own?

I seem to be confused on what is the right way to do this.

Btw, the two servers are running Suse Linux Enterprise Edition 9...

migrated from stackoverflow.com Jun 2 '11 at 0:53

This question came from our site for professional and enthusiast programmers.

  1. No, you keep id_rsa to yourself; however, id_rsa.pub, which is your public key, may be copied to servers to which you wish to have access. Concatenate them onto the end of ~/.ssh/authorized_keys.
  2. Yes, you may create ~/.ssh/authorized_keys if it is not already created; otherwise, just append to the end of the file, using cat id_rsa.pub >>~/.ssh/authorized_keys.

Also there is a tool that sorts all this for you called ssh-copy-id.

It will append the key in your agent if you have one running to the authorized_keys file and create it if it does not exist with the right permissions. If you aren't running an agent you can specify the key to push with -i: ssh-copy-id -i ~/.ssh/id_rsa


You should also check the permissions on the various files and directories:

authorized_keys needs perms of 600 (chmod 600 authorized_keys)
the .ssh directory should be 700
your home directory should be at most 744

Your home directory must not be writable by anyone other than you.


In case you configure the key generated from ssh-keygen but still password less transfer doesn't work, then verify the public key used on source machine in verbose mode command as below:

sftp -v -oPort=22 userid@server

Usually it refers to public key at /home/<user>/.ssh/id_rsa.pub which might be different from one you generated using ssh-keygen. You need to add this id_rsa.pub at destination server.


I would do the following:

On the client:

ssh-keygen -t rsa
ssh-copy-id oracle@

This copys the key from the client to the server. You will need the password of the server to make it add your key to its ring.

  • Password Authentication either needs to be on or you need to hand deliver the keyfile to the server.

On the Server:

I would at the vary least, turn off Password Authentication.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy