使用秘钥登录服务器

一。更新服务器  yum -y update

二。建立密钥对(密码可空)

[root@VM_14_49_centos ~]#ssh-keygen
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:
f8:22:a6:0a:ef:62:59:ef:84:49:1a:c7:6d:47:6c:79 root@VM_14_49_centos

三。查看秘钥对

[root@VM_14_49_centos ~]# cd .ssh/
[root@VM_14_49_centos .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub
[root@VM_14_49_centos .ssh]# cat id_rsa.pub >> authorized_keys   //注册公钥
[root@VM_14_49_centos .ssh]# chmod 700 ~/.ssh                    //修改文件夹权限,不修改可能会出现权限不够登录不进来
[root@VM_14_49_centos .ssh]# chmod 600 authorized_keys           //修改文件权限,不修可能会出现权限不够登录不进来
[root@VM_14_49_centos .ssh]#

    1.  authorized_keys :在这里注册公钥

    2.  id_rsa :这是私钥, 用来在外部登录服务器(自已保管好)

    3.  id_rsa.pub :这是公钥,复制进 authorized_keys 注册

四。打开秘钥登录

[root@VM_14_49_centos ~]# vim /etc/ssh/sshd_config
修改: RSAAuthentication yes PubkeyAuthentication yes //打开秘钥登录 PermitEmptyPasswords no //root禁止SSH登录(确保有root权限的账户) PasswordAuthentication no //禁用密码登录(要先确保密钥能登录)

五。重启ssh服务

[root@VM_14_49_centos ~]# service sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
[root@VM_14_49_centos ~]# 

 

转载于:https://www.cnblogs.com/GH-123/p/7965852.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值