Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am currently using this command. I am on another machine (ip1)

scp file.txt root@ip2:/home/praveen/test.c /home/praveen

The command will prompt for password.

I use it in some shell scripts, and am calling these scripts from some crontab files. So, I can not enter the password every time. Is there any way to disable password asking or some another way to input password from somewhere, so that I don't need to enter it again.

And I cannot use ssh-keygen, because I have to do the actions for these scripts only. When I use ssh-keygen, it will never prompt me for password again. I don't want this. Rest of the things should work as usual.

share|improve this question
2  
You need to configure public/private key authentication for your host/client. –  val0x00ff Aug 27 '13 at 9:01
    
See this Q&A for tips and resources on how to setup public/private key auth: unix.stackexchange.com/questions/47723/… –  slm Aug 27 '13 at 9:01
    
possible duplicate of SCP from one server to another without password prompt –  slm Aug 27 '13 at 9:02
    
You asked this question in toolbox.com later and you got the answer I think. –  Sepahrad Salour Aug 27 '13 at 9:27
1  
This is not a duplicate, the OP specifically mentions that s/he does not want to use ssh-keygen. –  terdon Aug 27 '13 at 14:46

4 Answers 4

It was not clear why you could not use ssh-keygen and the subsequent key exchange. I believe this is the recommended practice.

An alternative would be to use the expect command (online man pages). This can eliminate user intervention in the interactive processes. As the name suggests, it expects a prompt, and responds accordingly as specified to it.

Look at this solution of automating SSH using expect. To quote a few lines:

# Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"

The second line specifies the prompt that appears. In this case, it asks for password. The fourth line sends the password to the server.

share|improve this answer
    
+1. Never heard of expect. Learned sth! –  mike Aug 27 '13 at 9:29
1  
This also leaks the password in the clear, just like Christos' answer. As @Barun is most definitely aware and just trying to answer your question, any method other than public/private keys is a bad idea. –  slm Aug 27 '13 at 14:00
    
This means writing the password in a file, which is even worse than having a passwordless private key. –  Gilles Aug 27 '13 at 21:49

Since nobody posted an actual answer.

Yes, as denoted in the comments. You need to a create public/private keys pair.

Here are 2 manuals:

You then can utilize ssh-agent to load the keys into memory, in that way you don't have to enter the password you specified for the keys - since they get stored in memory for the current session. You don't have to set a password in first place, but I would recommend to do so, since persons holding your private key could use it to compromise you.


Of course you can delete the keys afterwards or delete your public key from ~/.ssh/authorized_keys on the remote host. He will then prompt you for pw again.

share|improve this answer

You could use ftp, if that's allowed on the remote server. Here's a sample of shell script I used for this purpose

HOST='remote.server.com'
USER='domainname/usrid'   
PASSWD='p@@ssw0rd'
cd /path/to/local/directory/containing/the/file/to/be/transferred
`ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd /diretory/on/remote/server
put file2transfer.dat 
bye    
quit
END_SCRIPT`
share|improve this answer

A simple solution is:

echo "password" | scp -r myfile user@remotehost:/home/user/destination 
share|improve this answer
    
Indeed simple. But I don't know where OP works, or if it's private. But having the pw in plaintext in a script or even in his command history seems a little bit unsecure. –  mike Aug 27 '13 at 9:20
1  
Yes this works, but it's a bad idea. The password is sent in the clear, better to use public/private keys! –  slm Aug 27 '13 at 13:57
    
Does it work? Most things that prompt for a password directly use the users tty, which is part of why expect was created in the first place. That is beyond the fact that it's a bad idea to start with. –  kurtm Oct 13 '13 at 5:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.