本篇文章可以解决云云主机之间的文件传输,windows和云主机之间的文件传输
我有两台云主机,我想从主机A传文件到主机B
[root@VM-4-10-centos ~]# scp /mytest/Dockerfile root@123.123.123.123:/usr
root@123.123.123.123's password:
Dockerfile
主要是第一条.scp命令, 资源路径 另外一台主机的用户名@地址 目标路径
这个每次传输都需要输另外一台机器对象的用户密码,可以提供ssh认证,以后不用输密码啦
ssh-keygen -t rsa
[root@VM-4-10-centos /]# ssh-keygen -t rsa
Generating public/private rsa key pair.
//需要保存在哪,默认的就是下面这个,可以为空
Enter file in which to save the key (/root/.ssh/id_rsa):
//给个加密的短语,可以为空
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:zQ+nwjcFz9fm1wPX5Ran9Z3I/Q4PdseREh/uedMKajI root@VM-4-10-centos
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| . . o+|
| o +. *=@|
| S + ==oOO|
| . * .==*|
| o + o +=@|
| Eo.o o B*|
| +. . o|
+----[SHA256]-----+
[root@VM-4-10-centos /]#
生成密钥之后发送到主机B上
ssh-copy-id root@123.123.123.123
好了大概就是这个样子
[root@VM-4-10-centos /]# ssh-copy-id root@123.123.123.123
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@123.123.123.123's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@123.123.123.123'"
and check to make sure that only the key(s) you wanted were added.
再次传输需要输入前面生成rsa时加进去的密码.如果当时没有,这里应该也不用填,猜测
[root@VM-4-10-centos /]# scp /mytest/Dockerfile root@123.123.123:/usr
Enter passphrase for key '/root/.ssh/id_rsa':
Dockerfile 100% 88 11.7KB/s 00:00
[root@VM-4-10-centos /]# scp /mytest/Dockerfile root@123.123.123:/usr
Enter passphrase for key '/root/.ssh/id_rsa':
Enter passphrase for key '/root/.ssh/id_rsa':
Dockerfile 100% 88 11.3KB/s 00:00
[root@VM-4-10-centos /]#
如果有不通,需要注意防火墙和端口暴露.
关于windows PowerShell 远程传输碰到的一些问题
scp /aa.txt root@123.123.12.12:/usr
ssh: connect to host 106.14.118.226 port 22: Connection timed out
lost connection
这里有个连接超时.但是上面我才用另外一台云主机连通了.所以猜测问题出在我本地我的电脑系统是win10.自带了openSSH.大家都可以核对一下
接下来查看防火墙,发现没有允许通过,问题就出在了这里.openssh的路径基本都是在这个位置C:\Windows\System32\OpenSSH.建议把scp和ssh都加进去.然后就可以快乐互传了