Linux[CentOS 7]免密登陆

2018-10-18 14:00 By "Powerless" 3049 0 3

一、修改sshd_config

vim /etc/ssh/sshd_config

找到以下内容,删除#

RSAAuthentication yes 
PubkeyAuthentication yes 
AuthorizedKeysFile .ssh/authorized_keys

修改好ssh的配置文件后保存并退出,重启SSH服务,这一步建议在公钥上传后再操作,不然你一旦断开了服务器,又没有允许登录的服务器公钥,后果...嘿嘿嘿

systemctl restart sshd.service


二、客户端生成公钥,执行下面的命令

ssh-keygen -t rsa

提示Generating public/private rsa key pair.

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

    输入要保存密钥的文件(/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

    输入密码(无密码短语为空):

Enter same passphrase again:

    再次输入相同的密码:

一般情况下我们会直接按3次回车。默认会在 ~/.ssh目录生成两个文件: id_rsa私钥,id_rsa.pub公钥。known_hosts文件会记录ssh密钥登陆的主机列表。


三、导入公钥到认证文件,更改权限

    导入公钥到本机

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

    导入本地公钥,至免密码登录的远程服务器

scp ~/.ssh/id_rsa.pub xxx@host:/home/id_rsa.pub

然后,把公钥导入到认证文件(这一步在服务器进行)

cat /home/id_rsa.pub >> ~/.ssh/authorized_keys

在服务器上更改文件权限

chmod 700 ~/.ssh 

chmod 600 ~/.ssh/authorized_keys


到此,配置完成。快去试试能不能连接成功吧

评 论

View in WeChat

Others Discussion

  • 初识七层、五层、四层网络协议
    Posted on 2021-04-09 16:52
  • Redis各种数据类型的使用场景举例分析【二】
    Posted on 2018-11-22 10:30
  • QPS、TPS、RT、吞吐量到底是什么
    Posted on 2020-02-02 01:15
  • 2018年云计算热词
    Posted on 2019-06-12 18:19
  • Linux工具 - NM目标文件格式分析
    Posted on 2019-04-24 10:29
  • ACID原则
    Posted on 2020-12-17 16:36
  • 前端知识体系精简-Css
    Posted on 2018-03-28 18:34
  • 浏览器访问网站经历的步骤-Html
    Posted on 2018-11-28 18:48