您的位置:首页 > 运维架构 > Linux

服务器ssh_key授权,并禁止密码登陆

2017-03-13 11:52 281 查看

·生成rsa_key , 并添加公钥到服务器

windows:

下载XSHELL,在登陆的时候可以选择用密钥登陆, 然后直接生成,保存可以得到rsa_key.pub。

linux or Mac:

1、生成SSH密钥对

ssh-keygen -t rsa


2、建议直接回车使用默认路径

Enter file in which to save the key (/root/.ssh/id_rsa):


3、输入密码短语(留空则直接回车)

Enter passphrase (empty forno passphrase):


4、重复密码短语

Enter same passphrase again:


最后会显示生成的路径

Your identification has been saved in/root/.ssh/id_rsa.
Yourpublic key has been saved in/root/.ssh/id_rsa.pub.


·添加res_key到服务器

打开刚才生成的.pub文件,复制里面内容 , 在服务器里面输入

echo "XXX(.pub里面所有的内容)" >> /root/.ssh/authorized_keys


·禁止密码登陆,并启动ssh_key验证

1、编辑sshd_config文件

vi /etc/ssh/sshd_config


2、禁用密码验证

PasswordAuthentication no


3、启用密钥验证

RSAAuthentication yes
PubkeyAuthentication yes


重启服务

RHEL/CentOS系统:
service sshd restart

Ubuntu系统:
service ssh restart

debian系统:
/etc/init.d/ssh restart
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux