Linux云服务器初学之二 ——熟悉linux的秘钥工具
配置CentOS**验证登录
1.在远程服务器上创建**对。
[[email protected]_0_5_centos ~]# ssh-****** -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:
c9:87:f1:c4:67:08:02:d7:fe:f9:ef:97:1a:3e:dc:44 [email protected]_0_5_centos
The key’s randomart image is:看到一个RSA的图就说明远程服务器上的私钥创建成功。
2.将远程服务器上的私钥下载到本地用于登录远程服务器
将生成的秘钥移动到home文件夹并导到windows上
[[email protected]_0_5_centos .ssh]# mv id_rsa /home/
我使用的是WinSCP获取的文件
3.把秘钥移到指定的文件夹并编辑配置文件
[[email protected]_0_5_centos .ssh]# mkdir ./ssh
[[email protected]_0_5_centos .ssh]# cp id_res.pub authorized_keys
[[email protected]_0_5_centos .ssh]# cp /root/.ssh/authorized_keys /.ssh/authorized_keys
[[email protected]_0_5_centos .ssh]# chmod 644 /.ssh/ #赋予其权限
[[email protected]_0_5_centos .ssh]# vim /etc/ssh/sshd_config
#修改如下四行
ServerKeyBits 1024#修改强度为1024
PermitRootLogin yes #允许root用户登录
RSAAuthentication yes #启用RSA认证
PubkeyAuthentication yes #启动公钥认证
AuthorizedKeysFile /.ssh/authorized_keys #公钥的存放文件夹
4.使用刚才创造的秘钥登录
先导入刚才用SCP导出的私钥
再在用户登录页面内使用public key 登录
如果需要填写密码,则是你秘钥生成时候的密码
5.设置禁止密码登录
[[email protected]_0_5_centos .ssh]# vim /etc/ssh/sshd_config
PasswordAuthentication no
这样就可以禁止密码登录了
采用公钥和私钥的用处
之后就采用秘钥和公钥方式去登录你的linux云服务器了。使用 ssh 的公钥**实现自动登陆可以让你免于输入密码,不但增加了便捷性也更加安全