标签云

微信群

扫码加入我们

WeChat QR Code

I know it is not recommended, but is it at all possible to pass the user's password to scp?I'd like to copy a file via scp as part of a batch job and the receiving server does, of course, need a password and, no, I cannot easily change that to key-based authentication.


See also (later) question: stackoverflow.com/questions/1462284/… where one answer mentions another possible way to do this.(NB: this is not a duplicate question - it is the original which the other duplicates.)

2019年05月27日06分23秒

Link to expect.nist.gov is broken. Maybe this?: expect.sourceforge.net

2019年05月27日06分23秒

sudo apt-get install expect

2019年05月27日06分23秒

Link changed to core.tcl.tk/expect/index

2019年05月27日06分23秒

>> brew info sshpassError: No available formula with the name "sshpass"We won't add sshpass because it makes it too easy for novice SSH users to ruin SSH's security.;)

2019年05月27日06分23秒

On Ubuntu 12.04 it only worked for me with single quotes over the password (e.g. 'password' instead of "password").

2019年05月27日06分23秒

odedfos, yes you need to use single quotes because some password generated chars can have a special interpretation in double quoted string interpolation

2019年05月27日06分23秒

This is how you install sshpass apt-get install sshpass

2019年05月27日06分23秒

On CentOS it's yum -y install sshpass

2019年05月27日06分23秒

The most secure way to do this is with a password file, like this: sshpass -f passwdfile` scp [...]. This way, the password won't show up in ps` listings, etc. and you can protect the password with file permissions.

2019年05月27日06分23秒

As I wrote: No, I cannot easily switch to key-based authentication.

2019年05月27日06分23秒

Do you mean .authorized_keys rather than . authorization_keys?

2019年05月28日06分23秒

A valid use for this would be a bash script that does multiple scp/ssh calls to a server where you want to ask the user for the password for the remote server.The password will then not show in history and you still have the befit of challenging for the password... but only once.I don't want to use a key file because I want to still authenticate the script user.

2019年05月27日06分23秒

Another valid use would be if you cannot easily enable key-based authentication on the target. Example: One of the main NAS producers - Synology with their DSM 6.0 - does not support it even in 2016. Sure, you could mess with configuration files and hope an update won't just overwrite it again (updating DSM frequently does break custom modifications). Sometimes - especially when the OP expressly writes they're already aware it's not optimal - people just need a solution.

2019年05月27日06分23秒

You should use ssh-copy-id -i ~/.ssh/id_rsa.pub <remote_server> to copy the key on the remote server

2019年05月27日06分23秒

Show an example, please.

2019年05月27日06分23秒

Also, might want to add C:\Program Files (x86)\PuTTY to your path to use these commands.

2019年05月27日06分23秒

SDsolar here's a syntax example: pscp -pw 'MyPa$$word' usernameservername:/somedir/somefile ~/somedest (I hate using putty like this, but it works)

2019年05月27日06分23秒

Prerequisite: sudo apt-get install expect

2019年05月27日06分23秒

It quite slower than 'scp' but it does the job fine.

2019年05月27日06分23秒

I found this to be faster when the destination is configured with a huge password prompt delay.scp has to wait 30+ seconds to let me put in a password, but curl worked immediately.

2019年05月27日06分23秒

Being a Linux noob, what does this run in?Bash doesn't accept sub...

2019年05月27日06分23秒

This is in perl, sorry i didn't write that. (5 years ago :) )

2019年05月27日06分23秒

It was mentioned in user524607's answer 5 years ago.

2019年05月27日06分23秒

Please show an example.

2019年05月27日06分23秒

Found it, and am adding C:\Program Files (x86)\PuTTY to my path.

2019年05月27日06分23秒

The question said he can't use key-based authentication.

2019年05月27日06分23秒

Also, if it were me, I assume I can't alter the other server - all I want is to copy a file.

2019年05月27日06分23秒

and how exactly are you providing password here?

2019年05月27日06分23秒