在Linux服务器之间使用ssh命令向另一个Linux服务器发送执行指令是需要输入密码
![](http://upload-images.jianshu.io/upload_images/4973658-b2cd922f4151e77e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/469/format/webp)
ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式。其中口令(密码)认证方式是我们最常用的一种,这里介绍密钥认证方式登录到linux/unix的方法。
使用密钥登录分为3步:
1、生成密钥(公钥与私钥);
使用ssh-keygen -t rsa
![](http://upload-images.jianshu.io/upload_images/4973658-f54a54b0cf2c0c11.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/680/format/webp)
生成公钥,秘钥
使用scp 命令将本机的公钥id_rsa.pub发送至目标Linux服务器(因为还未完成免密码登陆所以scp命令需要密码)
scp ~/.ssh/id_rsa.pub root@192.168.220.129:~/
2、放置公钥到服务器(192.168.220.129)~/.ssh/authorized_key文件中;
![](http://upload-images.jianshu.io/upload_images/4973658-b266af8c748e7077.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/540/format/webp)
![](http://upload-images.jianshu.io/upload_images/4973658-d7bc3b1f2bc3c89f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/506/format/webp)
将id_rsa.pub文件添加经authorized_keys文件
![](http://upload-images.jianshu.io/upload_images/4973658-a87d603edba3a893.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/879/format/webp)
![](http://upload-images.jianshu.io/upload_images/4973658-d20867456407f78e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/694/format/webp)
无需密码直接执行ssh命令
大功告成现在使用shh scp 命令 操作 129.169.220.129的服务器不用再输入密码
文章转载至:https://www.jianshu.com/p/14f74b142d31