Operating System - Linux
1745911 Members
4340 Online
108723 Solutions
New Discussion юеВ

Supplying password and user name to scp command

 
Karthik_sg
Frequent Advisor

Supplying password and user name to scp command


Hi all,
Can any one tell me how to copy a file in a remote machine through any script.Provided the username and password are given with the following command:

scp root@15.02.5.5:/home/jaguar/file.txt /home/have

Please explain how to supply the password in the script.Thanks in advance
4 REPLIES 4
Ivan Ferreira
Honored Contributor

Re: Supplying password and user name to scp command

Two options:

- Use public key authentication
- Use expect script

Recommendation:

Disable root access for SSH.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Karthik_sg
Frequent Advisor

Re: Supplying password and user name to scp command

Can u give any me any sample code for expect script.Thanks.
Andrew Cowan
Honored Contributor

Re: Supplying password and user name to scp command

Login as the user that will be doing the transfer on each of the systems and run "ssh-keygen". Set a blank passphrase and save the keys in the default location "~/.ssh".

Copy the "id_[r|d]sa.pub" (public key) of each of the systems to the other and then add/append them to the "~/.ssh/authorized_keys". Make sure that the key is one continuous line and does not contain 's, as this won't work.

Also ensure that the permissions are correctly set on the ".ssh 0700", "id_rsa 0600", "id_rsa.pub 0644".

To test try SSH and SCP as this user in both directions. if there is a problem run "ssh -v" to see the debug output.

Good luck,
Andrew
Steven E. Protter
Exalted Contributor

Re: Supplying password and user name to scp command

Shalom,

ssh-key-gen -t dsa

copy the id_dsa.pub file to the target system and append it to the $HOME/.ssh/authorized_keys file

Make sure the owner of the home and .ssh directories is consistent with the user that lives there.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com