1、将本地文件拷贝到远端scp文件用户@主机名:远端目录[email protected]:/2、将远端目录拷贝到本地scp-r用户@主机名:远端目录本地目录scp-rroot@19
.
1、将本地文件拷贝到远端
scp 文件 用户@ 主机名:远端目录scp 123.txt [email protected]:/
2、将远端目录拷贝到本地
scp -r 用户@主机名:远端目录 本地目录scp -r [email protected]:/456.txt ~
3、SCP无需输入密码传输文件
在Linux环境下,两台主机之间传输文件一般使用scp命令,通常用scp命令通过ssh获取对方linux主机文件的时候都需要输入密码确认。
不过通过建立信任关系,可以实现不输入密码。
1)在其中一台主机上执行如下命令来生成配对密钥:
ssh-keygen -t rsa
按照提示操作,注意,不要输入passphrase。提示信息如下
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:63:61:d2:ce:5f:e8:14:5c:56:2c:7b:08:71:41:a2:cc [email protected]
2.)将 .ssh 目录中的 id_rsa.pub 文件复制到另外一台主机的 ~/.ssh/ 目录中,并改名为 authorized_keys。
scp .ssh/id_rsa.pub 主机名:/root/.ssh/authorized_keys.