How to pass the password as input parameter to scp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass the password as input parameter to scp
# 1  
Old 03-13-2012
How to pass the password as input parameter to scp

Dear all

Does anybody know how to pass the password as input parameter to scp or rsync in unix scripts?

I have tried echo <password> | scp filename username@<ip address>:/filepath/ .
But it does not work.

BTW, I dont want to setup ssh trust between servers in this adhoc task.

Regards,
eldon
# 2  
Old 03-13-2012
scp and rsync are designed to detect that their password input isn't comming from a terminal to stop just this sort of thing.

I would say the developers of these products thought it was a bad thing for account passwords being visible on ps listings or in human readable files.

If you really insist on doing this sort of thing the expect tool is probably the way you will need to go, or just setup public/private key authentication between the accounts (it's not that hard and will be much more portable/safe).
# 3  
Old 03-13-2012
One reason those methods of authentication are not considered as worthwhile is that they mean you are keeping your password or passphrase stored somewhere in the clear, or in a way a program can decrypt them without verifying you are there. But for automated things, sometimes you just have to do some of this.

I recommend using keys with ssh. You can encrypt the private keys with a passphrase that ssh-agent can open for you once (per reboot or login) and all further uses, like the overnight backup, can just get it from the agent. Or if you trust your machine's physical security (not recommended for laptops taken from home or office) just leave it unencrypted. You can also do what I do and have authorize two or more extra keys at the login destination and hide extras on USB memory sticks with obscure names. Other options include have separate keys for interactive access and automated access (if the automated access key gets into someone else's hands you still have your server access via the interactive key with you you can revoke the authentication of the other key, and put in a new one).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How pass the input parameter to a file in the script ?

OS version: RHEL 6.7 myTextFile.txt file is referred within Script1.sh script, I only execute Script1.sh and I want the input variable to be passed inside myTextFile.txt . Any idea how I can do this ? $ cat script1.sh cat myTextFile.txt $ cat myTextFile.txt $1 Requirement1.... (4 Replies)
Discussion started by: kraljic
4 Replies

2. Shell Programming and Scripting

How to pass password and prompt user for IP address while doing ssh and scp?

Hi All, I want to copy /.ssh/OM.pub file from source to destination. Here source IP address, username and password is always fixed. Whereas destination server IP address, password always gets changed. From destination server :- I am trying to write a script in which it should log in to... (3 Replies)
Discussion started by: madhur.baharani
3 Replies

3. Shell Programming and Scripting

Pass parameter

Hi, I have following for loop , please let me know how to get ${TXP_EXT_TABLE_${i}_SQL} parameter with 1DAY and 7DAY values. for i in 1DAY 7DAY do ${NZSQL_DIR}/nzsql -h ${HOST} -time -v ON_ERROR_STOP=1 -f ${SQL_DIR}/${TXP_EXT_TABLE_${i}_SQL} > ${TMP_LOG_FILE} 2>&1 done ... (4 Replies)
Discussion started by: sandy162
4 Replies

4. Shell Programming and Scripting

How to pass two word parameter

Hi, How to pass parameter to run folloing script? #parameters are div, dept, style U run_convert_pdm.ksh Mens 44 7542 U run_convert_pdm.ksh "Mens Knit" 44 7541 The first command works fine but the second needs to have two words together , it does not work even if I have used double... (15 Replies)
Discussion started by: sandy162
15 Replies

5. UNIX for Dummies Questions & Answers

How to pass the parameter value to a... ?

Hello I have a simple code like this one: #!/bin/ksh VER=$1 cat /usr/text | while read line do echo $line done Let's say $1=1.0.0 and the contents of text is: abcd.cfg asdf I would like the output to be like this abcd1.0.0.cfg asdf1.0.0 I am thinking of passing the... (5 Replies)
Discussion started by: khestoi
5 Replies

6. Shell Programming and Scripting

Pass input and output file as parameter to awk script

Hi, i am new to awk. I am using csv2pipe script(shown below) BEGIN { FS=SUBSEP; OFS="|" } { result = setcsv($0, ",") print } # setcsv(str, sep) - parse CSV (MS specification) input # str, the string to be parsed. (Most likely $0.) # sep, the separator between the values. # #... (6 Replies)
Discussion started by: bhaskarjha178
6 Replies

7. Shell Programming and Scripting

How to pass a parameter

Hi all, How to pass a parameter from a oracle pl/sql procedure parameter to shell environment and use it? (1 Reply)
Discussion started by: megh
1 Replies

8. UNIX for Dummies Questions & Answers

PASS parameter to AWK

Hi, Can i pass a parameter(not a file name) as a parameter to a awk program? eg; $awk -f test 1 2 3 here test is the filename...and 1,2,3 are the i/p parameters? thank you:-) (2 Replies)
Discussion started by: unisam
2 Replies

9. UNIX for Dummies Questions & Answers

Pass Parameter to Another Script

I have a piece of code that I do not want to continuously repeat. I want to call script2 from script1 and pass a parameter. Here is an example: Script1: ....... nohup ./Script2 PARAMETER ....... Script2: if # Checks if any params. then echo "No parameters passed to function." ... (4 Replies)
Discussion started by: rvprod
4 Replies
Login or Register to Ask a Question