scp免密拷贝
scp免密拷贝
(1.)在A机器生成秘钥
ssh-keygen -t rsa -P ""
(2.) 拷贝A机器公钥到B机器
scp /root/.ssh/id_rsa.pub root@IP_B:/root
(3.) 登录B机器,拷贝id_rsa_pub内容到.ssh目录下的authorized_keys文件中
cat id_rsa.pub >> .ssh/authorized_keys
(4.) 测试
ssh root@IP_B或
scp test.txt root@IP_B:/home/
(5.)设置权限
# 设置authorized_keys的权限
chmod 600 ~/.ssh/authorized_keys
# 设置.ssh目录权限
chmod 700 -R ~/.ssh
(6.)修改sshd_config文件
vi /etc/ssh/sshd_config
Port 22
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication no
scp带密码拷贝
(1.)安装sshpass
# ubuntu16.04执行:
sudo apt-get install sshpass
# centos7执行:
yum -y install sshpass
# 源码安装
下载地址:http://sourceforge.net/projects/sshpass/
wget http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz
yum -y install gcc
tar xvzf sshpass-1.05.tar.gz
cd sshpass-1.05.tar.gz
./configure
make
make install
(2.)执行拷贝
sshpass -p 密码 scp -r 1.txt root@10.1.1.1:/root
sshpass -f 存放密码的文件 scp -r 1.txt root@10.1.1.1:/root
相关链接
https://www.cnblogs.com/youcong/p/10809056.html
【励志篇】:
古之成大事掌大学问者,不惟有超世之才,亦必有坚韧不拔之志。