linux - 如何将密码传递给scp?

标签 linux scp io-redirection

我知道不建议这样做,但是否可以将用户密码传递给 scp?

我想通过 scp 复制一个文件作为批处理作业的一部分,而接收服务器当然需要密码,不,我不能轻易将其更改为基于 key 的身份验证。

最佳答案

使用 sshpass :

sshpass -p "password" scp -r user@example.com:/some/remote/path /some/local/path

所以密码不会显示在 bash 历史记录中

sshpass -f "/path/to/passwordfile" scp -r user@example.com:/some/remote/path /some/local/path

以上将远程主机的路径内容复制到本地。

安装:

  • ubuntu/debian
    • apt install sshpass
  • centos/fedora
    • yum install sshpass
  • 带有 macports 的 mac
    • 端口安装 sshpass
  • mac w/brew
    • brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb

关于linux - 如何将密码传递给scp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50096/

相关文章:

linux - 检查所有目录中公共(public)子目录中的文件数

c - 如何在 C 中检索传递给 linux 系统调用的参数?

c - 使用 C 中的静态库重定向标准输出(例如到文件)

bash - 在 Bash 中通过变量重定向 STDOUT

linux - 如何使用 awk 或 sed 在 bash 中调整列字段的长度?

linux - 如何查找延迟的原因?

windows - SSH 和 SCP 失败,错误为 "CreateProcessW failed error:2 posix_spawn: No such file or directory"

linux - 获取 stty : standard input: Inappropriate ioctl for device when using scp through an ssh tunnel

linux - 是否可以将文件从本地 windows 目录复制到远程 linux 目录?

bash - 如何将多个命令的输出重定向到一个文件?