Bash:如何将文件从本地路径传输到 SSH 服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31844757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash: How to transfer file from local path to SSH server?
提问by user3125996
What does one have to write to copy a file from a local location, to a password-protected remote ssh server in a terminal/bash script using Linux?
使用 Linux 在终端/bash 脚本中将文件从本地位置复制到受密码保护的远程 ssh 服务器需要写什么?
For example:
例如:
Source: /home/bin/file.txt
来源:/home/bin/file.txt
Destination: [email protected]
回答by Brian Chow
SCP is designed to do this. Using your example:
SCP 就是为此而设计的。使用您的示例:
$ scp /home/bin/file.txt [email protected]:/path/to/store
If you want it scripted w/o requiring a password, you'll want to setup SSH keys for the user the script is running as. Digital Ocean has a good tutorial on how to setup SSH keys located here: How To Set Up SSH Keys
如果您希望脚本不需要密码,您需要为运行脚本的用户设置 SSH 密钥。Digital Ocean 有一个关于如何设置 SSH 密钥的很好的教程,位于此处:如何设置 SSH 密钥