Copying files from one machine to another without asking for password
Solution 1
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.
Solution 2
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`
Related videos on Youtube
user2706152
Updated on September 18, 2022Comments
-
user2706152 over 1 year
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 usessh-keygen
, it will never prompt me for password again. I don't want this. Rest of the things should work as usual.-
Marek Zakrzewski over 10 yearsYou need to configure public/private key authentication for your host/client.
-
slm over 10 yearspossible duplicate of SCP from one server to another without password prompt
-
Sepahrad Salour over 10 yearsYou asked this question in toolbox.com later and you got the answer I think.
-
terdon over 10 yearsThis is not a duplicate, the OP specifically mentions that s/he does not want to use
ssh-keygen
.
-
-
mike over 10 yearsIndeed 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 over 10 years+1. Never heard of
expect
. Learned sth! -
slm over 10 yearsYes this works, but it's a bad idea. The password is sent in the clear, better to use public/private keys!
-
slm over 10 yearsThis 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.
-
Gilles 'SO- stop being evil' over 10 yearsThis means writing the password in a file, which is even worse than having a passwordless private key.
-
kurtm over 10 yearsDoes 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.