我知道不建议这样做,但是是否有可能将用户的密码传递给scp?
我想通过scp复制一个文件,作为批处理作业的一部分,接收服务器当然需要密码,不,我不能轻易地将其更改为基于密钥的身份验证。
我知道不建议这样做,但是是否有可能将用户的密码传递给scp?
我想通过scp复制一个文件,作为批处理作业的一部分,接收服务器当然需要密码,不,我不能轻易地将其更改为基于密钥的身份验证。
当前回答
您可以使用像expect这样的工具编写脚本(也有方便的绑定,比如Python的Pexpect)。
其他回答
您可以在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
我希望这对你有所帮助。
上面提到的所有解决方案都可以工作,只有当你安装了应用程序,或者你应该有管理权限安装除sshpass。
我发现这个非常有用的链接可以简单地在后台启动scp。
$ nohup scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1
https://charmyin.github.io/scp/2014/10/07/run-scp-in-background/
我在这里找到了一个非常有用的答案。
rsync -r -v --progress -e ssh user@remote-system:/address/to/remote/file /home/user/
你不仅可以在那里传递密码,而且它还会在复制时显示进度条。真的太棒了。
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
只需生成一个SSH密钥:
ssh-keygen -t rsa -C "your_email@youremail.com"
复制~/.ssh/id_rsa.pub的内容 最后将它添加到远程计算机~/.ssh/authorized_keys
确保远程机器拥有~的权限0700。~/.ssh/authorized_keys文件夹为0600