scp and sftp either with or without a password using authorized keys

It is better to use scp/sftp rather than ftp – because ftp transmits passwords in plain text and also requires extra firewall openings to work.

1) Simplest way – use sftp specfiying the password in the script, like this:

lftp -u user:password sftp://server.domain.com << END_LFTP
put /directory/file.txt
quit
END_LFTP

Use the -O option to put onto a different directory:

put -O /target_dir /source_dir/file.txt

2) Other/better option is to use scp without a password:

scp -p /directory/file.txt user@targetserver.domain.com:.

If you are prompted for a password when doing the above, then add an authorized key:

[local] cat ~/.ssh/id_rsa.pub
[targetserver] vi ~/.ssh/authorized_keys  <= and add in the line from above

If there is no id_rsa.pub file on the local server, then generate one with:

[local] ssh-keygen -t rsa
June 5, 2013

  • Leave a Reply

    Your email address will not be published. Required fields are marked *