我知道不建议这样做,但是是否有可能将用户的密码传递给scp?
我想通过scp复制一个文件,作为批处理作业的一部分,接收服务器当然需要密码,不,我不能轻易地将其更改为基于密钥的身份验证。
我知道不建议这样做,但是是否有可能将用户的密码传递给scp?
我想通过scp复制一个文件,作为批处理作业的一部分,接收服务器当然需要密码,不,我不能轻易地将其更改为基于密钥的身份验证。
当前回答
从Windows以非交互方式使用SCP:
安装社区版netcmdlets 导入模块 使用Send-PowerShellServerFile -AuthMode password -User MyUser -Password not-secure -Server YourServer -LocalFile C:\downloads\test.txt -RemoteFile C:\temp\test.txt发送非交互式密码的文件
其他回答
如果您从Windows连接到服务器,Putty版本的scp(“pscp”)允许您使用-pw参数传递密码。
这里的文档中提到了这一点。
您可以在unix/terminal上使用'expect'脚本
例如,创建'test。经验值:
#!/usr/bin/expect
spawn scp /usr/bin/file.txt root@<ServerLocation>:/home
set pass "Your_Password"
expect {
password: {send "$pass\r"; exp_continue}
}
运行脚本
expect test.exp
我希望这对你有所帮助。
Make sure password authentication is enabled on the target server. If it runs Ubuntu, then open /etc/ssh/sshd_config on the server, find lines PasswordAuthentication=no and comment all them out (put # at the start of the line), save the file and run sudo systemctl restart ssh to apply the configuration. If there is no such line then you're done. Add -o PreferredAuthentications="password" to your scp command, e.g.: scp -o PreferredAuthentications="password" /path/to/file user@server:/destination/directory
没有人提到它,但是Putty scp (pscp)有一个-pw选项作为密码。
文档可以在这里找到:https://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter5.html#pscp
我有一个简单的方法:
使用相同的scp cmd,因为您使用ssh密钥,即
scp -C -i <path_to打开sshkey> <'local file_path'> user@<ip_address_VM>: <'remote file_path'>
用于从本地传输文件到远程
但是不要提供正确的<path_to_opensshkey>,而是使用一些垃圾路径。由于错误的密钥路径,您将被要求输入密码,而不是你现在可以简单地通过密码来完成工作!