,
,,,,平常使用ssh登陆远程服务器时,都需要使用输入密码,希望可以实现通过密钥登陆而免除输入密码,从而可以为以后实现批量自动部署主机做好准备。
,,,,环境如下:
强> 强> <强> 强> <强> 强>
,,,,生成密钥对:
xpleaf@leaf: ~,美元ssh-keygen -t rsa -b 2048 Generating 公共/private rsa key 一对。 Enter file  which 拷贝;用节省;从而key (/home/xpleaf/. ssh/id_rsa):, Created directory “/home/xpleaf/. ssh”。 Enter passphrase (empty for  no 密码):, 时间:Enter same  passphrase Your identification  has been  saved 拷贝/home/xpleaf/. ssh/id_rsa。 Your public  key has been  saved 拷贝/home/xpleaf/. ssh/id_rsa . pub。 从而key fingerprint 是: SHA256: eLssyXJLzUCfSN5mu6nqNH9dB/gOyXSvWBwQdNssIYE xpleaf@leaf ,关键's randomart  p_w_picpath 是: (RSA 2048) + - - - - - - - - - - - + |,,,,,,,,,o=oo ,, | |,,,,,,,,E .o =,, | |,,,,,,o ,,, oo o | |,,,,,+,=,.o +只,| |,,,,,,=,So =, +,, | |,,,,,,,B o +,=, o | |,,,,啊…=只*,o , | |,,,. . +=. . + o o ,, | |,,,. o + +==,,,,,,, | + - - - - - [SHA256] - - - - - - +
,,,,查看生成的密钥对:
xpleaf@leaf: ~,美元ls . ssh id_rsa id_rsa . pub #,id_rsa为私钥,这个一般需要保密;id_rsa。酒吧为公钥,这个可以公开。
,,使用scp命令操作:
xpleaf@leaf: ~,美元scp . ssh/id_rsa.pub root@10.0.0.128:/根 从而authenticity of  host “10.0.0.128 (10.0.0.128)”,可以't be 建立。 RSA key  fingerprint is  SHA256:0Tpm11wruaQXyvOfEB1maIkEwxmjT2AklWb198Vrln0。 断开连接;你sure 你;want 用continue connecting (yes/no)吗?是的 警告:,Permanently added “10.0.0.128”, (RSA),用,list of known 主机。 密码:root@10.0.0.128 's id_rsa.pub ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 100%, 393,,,,, 0.4 kb/s ,, 00:00
,
,,,,把从客户端传来的公钥添加到。ssh/authorized_keys中:
[root@leaf ~] #, cat id_rsa.pub 在祝辞. ssh/authorized_keys (root@leaf ~) #, chmod 600 . ssh/authorized_keys #,authorized_keys的权限需要为600年
,,,,修改ssh配置文件/etc/ssh/sshd_config,找到下面一行:
PubkeyAuthentication 没有
,,,,修改为:
PubkeyAuthentication 是的
,,,,在客户端上使用密钥登陆到服务器上:
xpleaf@leaf: ~,美元ssh 小姐;. ssh/id_rsa root@10.0.0.128 登录:Last Tue May , 9, 15:14:01 2017年,得到10.0.0.129 [root@leaf ~) #
- <李>
在服务器端需要把selinux关闭,否则最后无法使用密钥进行远程登陆;
李> <李>客户端使用scp命令时,在服务器端也需要安装ssh客户端,否则无法把公钥上传到服务器端,另外也可以使用ssh-copy-id root@10.0.0.128来代替scp操作(这样在服务器端也不需要执行创建。ssh目录等这些操作,即相当于该命令可以一步帮我们完成密钥的上传与配置工作);
李>