Bash scp 几个文件密码问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19164355/
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 scp several files password issue
提问by Matt
I am trying to copy several files from a remote server into local drive in Bash using scp. Here's the part of the code
我正在尝试使用 scp 将多个文件从远程服务器复制到 Bash 中的本地驱动器。这是代码的一部分
scp -r -q $USR@$IP:/home/file1.txt $PWD
scp -r -q $USR@$IP:/home/file2.txt $PWD
scp -r -q $USR@$IP:/root/file3.txt $PWD
However, the problem is that EVERY time that it wants to copy a file, it keeps asking for the password of the server, which is the same. I want it to ask only once and then copy all my files.
但是,问题是每次要复制文件时,它都会不断询问服务器的密码,这是相同的。我希望它只询问一次,然后复制我的所有文件。
And please, do not suggest rsync nor making a key authentication file since I do not want to do that. Are there any other ways...? Any help would be appreciated
并且请不要建议 rsync 或制作密钥身份验证文件,因为我不想这样做。有没有其他办法……?任何帮助,将不胜感激
回答by w00d
You can use expect
script or sshpass
您可以使用expect
脚本或sshpass
sshpass -p 'password' scp ...
sshpass -p 'password' scp ...
#!/usr/bin/expect -f
spawn scp ...
expect "password:"
send "ur_password"
An disadvantage is that your password is now in plaintext
一个缺点是你的密码现在是明文
回答by Gigline
I'm assuming that if you can scp files from the remote server, you can also ssh in and create a tarball of the remote files.
我假设如果你可以从远程服务器 scp 文件,你也可以 ssh 并创建远程文件的 tarball。
The -r flag is recursive, for copying entire directories but your listing distinct files in your command, so -r becomes superfluous.
-r 标志是递归的,用于复制整个目录但在命令中列出不同的文件,因此 -r 变得多余。
Try this from the bash shell on the remote system:
从远程系统上的 bash shell 试试这个:
$ mkdir /home/file_mover
$ cp /home/file1.txt /home/file_mover/
$ cp /home/file2.txt /home/file_mover/
$ cp /root/file3.txt /home/file_mover/
$ tar -cvf /home/myTarball.tar /home/file_mover/
$ scp -q $USR@$IP:/home/myTarball.tar $PWD
回答by Hyman
Well, in this particular case, you can write...
好吧,在这种特殊情况下,您可以编写...
scp -q $USR@$IP:/home/file[1-3].txt $PWD