Linux[CentOS 7]免密登陆

2018-10-18 14:00 By "Powerless" 3024 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

  • 2016年云计算热词
    Posted on 2019-06-12 17:53
  • 能创建多少个 TCP 连接?
    Posted on 2021-08-02 16:00
  • MySQL中的行级锁,表级锁,页级锁
    Posted on 2018-08-25 11:00
  • 投票通过,PHP 8 确认引入 Union Types 2.0
    Posted on 2019-11-18 22:22
  • PHP没你想的那么差
    Posted on 2021-12-17 15:40
  • 通过信鸽来解释HTTPS
    Posted on 2018-10-22 13:56
  • PHP练习-移动数组内的0到最后并保持其他元素顺序不变
    Posted on 2020-08-14 20:32
  • 快速了解Kafka
    Posted on 2021-03-25 14:20