我知道不建议这样做,但是是否有可能将用户的密码传递给scp?
我想通过scp复制一个文件,作为批处理作业的一部分,接收服务器当然需要密码,不,我不能轻易地将其更改为基于密钥的身份验证。
我知道不建议这样做,但是是否有可能将用户的密码传递给scp?
我想通过scp复制一个文件,作为批处理作业的一部分,接收服务器当然需要密码,不,我不能轻易地将其更改为基于密钥的身份验证。
当前回答
Curl可以用作SCP的替代方案来复制文件,并且它支持在命令行上设置密码。
curl --insecure --user username:password -T /path/to/sourcefile sftp://desthost/path/
其他回答
将文件从一个服务器复制到另一个服务器(在脚本上)
在ubuntu或其他Linux机器上安装putty。Putty随pscp附带。我们可以用pscp复制文件。
apt-get update
apt-get install putty
echo n | pscp -pw "Password@1234" -r user_name@source_server_IP:/copy_file_path/files /path_to_copy/files
有关更多选项,请参阅pscp help。
您可以在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
您可以使用以下步骤。这对我很管用!
步骤1 - 创建一个普通的文件,假设“fileWithScpPassword”,其中包含目标服务器的ssh密码。
Step2-使用sshpaas -f后跟密码文件名,然后是正常的scp命令。
sshpass -f“scppassword”scp / filepathtou上传user@ip:/目的地目的地/