LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   scripting a password for scp (https://www.linuxquestions.org/questions/linux-software-2/scripting-a-password-for-scp-591915/)

kennmurrah 10-15-2007 08:27 AM

scripting a password for scp
 
I want to write a short script that will, among other things, copy some files to a different server via scp. Doing this from the command line is easy, but if I want to script it, how do I incorporate the password into my script so that I can run it without being asked for the password (e.g. via cron)?

Thanks.

Kenn

whitemice 10-15-2007 08:40 AM

Don't
 
Quote:

Originally Posted by kennmurrah (Post 2924727)
I want to write a short script that will, among other things, copy some files to a different server via scp. Doing this from the command line is easy, but if I want to script it, how do I incorporate the password into my script so that I can run it without being asked for the password (e.g. via cron)?
Kenn

Don't!

SSH supports certificate authentication, and this is widely used and documented. Just generate an SSH key pair, put your public key on the server you are SCPing to and SCP & SSH will no longer as for a password as you will be 'pre-authenticated'.

kennmurrah 10-15-2007 09:01 AM

Thanks for the response ... two questions.

1. If I want to throw caution to the wind and do it, is it possible?

2. Could you point me in the direction of a how to that would help me do it your (proper) way?

thanks again.

Kenn

matthewg42 10-15-2007 09:43 AM

For the proper way, you should set up public key authentication. Here's how.

The "wrong" way to do it is to use expect. expect is a library which allows a program to pretend to be a user at a terminal, watch for patterns in the output of the program which is being run, and send commands accordingly. It can also attach the real user to the program. This is, in general the wrong approach for login automation as expect will have to store the account password somewhere, and this is very difficult to do in a secure way.

kennmurrah 10-15-2007 09:47 AM

Thanks to all.

Kenn


All times are GMT -5. The time now is 07:36 AM.