Tuesday, 12 April 2011

SCP scripting without password

To transfer files from one unix server (Server A) to another unix server (Server B), we usually use SCP command:
scp user@ServerB:/home/user/test.txt /home/user/
However, it always prompt for password, which is very bad for scripting.

YES! There is some solution, i.e. to be authorized in the destination server. Here is step-to-step procedures to achieve this:

1. Generate public/private key pairs in home/user/.ssh in Server A:
ssh-keygen -t rsa


2. Copy id_rsa.pub in Server A to home/user/.ssh/authorized_keys2 in Server B:
scp .ssh/id_rsa.pub user@ServerB:/home/user/.ssh/authorized_keys2
The system will prompt for user password at this stage.

Note: The destination file should be authorized_keys for SSH protocol version 1, or authorized_keys2 for SSH protocol version 2.

3. Make sure that permissions for .ssh directory in both servers are set to 700.
- To view permission
ls  -ld .ssh
- To change permission
chmod 700 .ssh

Done! Now SCP won't prompt password again during file copy.

For more command about file transfer using Linux or Unix, e.g. ftp, sftp, wget etc.,  you may visit http://aruljohn.com/info/filetransfer/

7 comments:

  1. Code for sync files:
    rsync -avz -e ssh user@ServerB:/home/user/folder/ /home/user/folder/
    or
    rsync -avz -e ssh user@ServerB:/home/user/folder/*.txt /home/user/folder/

    ReplyDelete
  2. I got what you mean , thanks for posting .Woh I am happy to find this website through google. Folder Lock PC App Gallery - Don't Waste Time Looking, Study Information On PC Devices Right here how to password protect my photo album ipad

    ReplyDelete
  3. I want to thank you for this excellent read!! I certainly loved every little bit of it. I've got you saved as a favorite to check out new things you post…
    Important site: Top Encryption Software Guide! & How To Learn To How To Encrypt A Password For Free Just 10 Minutes A Day

    ReplyDelete
  4. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts.
    Cyber Security Projects for Final Year

    JavaScript Training in Chennai

    Project Centers in Chennai

    JavaScript Training in Chennai

    ReplyDelete