linux之秘钥登录

Posted 入门小站

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux之秘钥登录相关的知识,希望对你有一定的参考价值。

两台主机(服务器)秘钥登录流程图

A主机生成公钥

> 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:
SHA256:+ims1qKnA9kAUbwuaGmGLdg+V4w1PMj7RO4gMHI7NCU root@JD
The keys randomart image is:
+---[RSA 2048]----+
|.+.              |
|. E .            |
|.  = o           |
|= = o *          |
|=%.o B oS        |
|O=O + =.         |
|+= o O.          |
|  + = *. .       |
|  oO.o .o        |
+----[SHA256]-----+
> ls -al ~/.ssh
-rw-------   1 root root  1675 May  7 21:39 id_rsa //私钥
-rw-r--r--   1 root root   389 May  7 21:39 id_rsa.pub //公钥

> cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDULg8kwT2rW8Z/r0h5lvO6KziZWV1roM/0eKVnkxeKOF9A0JAL46WF4ZA2XsNfG2camxTekC0ZwArB6uvFQTR8RZtDCwdsdsdsds6K3ytR/FOzira6z+7xbk6LvPylaCLfjfMmta04Q7dsdsdsdsdsds5MDr7oY73TWt2XToDA3FynMnl9MQjO4SoTU/Z1PiKsdOoCnbeP/O6KL+6sh9tbd5HoPPLm8LtDCeebZNhvZSulsbeTFZ5Z+HzPLostXJVhRFtiwUlaemAhXngVdIB5D9feXCYdQiP3NM0zAI94XUFCFyaSnZdv3+OTqHmxJ root@local

B服务器添加A主机的公钥

> cat /home/rumenz/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDULg8kwT2rW8Z/r0h5lvO6KziZWV1roM/0eKVnkxeKOF9A0JAL46WF4ZA2XsNfG2camxTekC0ZwArB6uvFQTR8RZtDCwdsdsdsds6K3ytR/FOzira6z+7xbk6LvPylaCLfjfMmta04Q7dsdsdsdsdsds5MDr7oY73TWt2XToDA3FynMnl9MQjO4SoTU/Z1PiKsdOoCnbeP/O6KL+6sh9tbd5HoPPLm8LtDCeebZNhvZSulsbeTFZ5Z+HzPLostXJVhRFtiwUlaemAhXngVdIB5D9feXCYdQiP3NM0zAI94XUFCFyaSnZdv3+OTqHmxJ root@local
> chmod 600 /home/rumenz//.ssh/authorized_keys
> chmod 700 /home/rumenz/.ssh

sshd服务安全配置

> vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes

重启sshd服务

> service sshd restart

密钥方式登录成功后,再禁用密码登录

> vim /etc/ssh/sshd_config
PasswordAuthentication no

> service sshd restart

秘钥登录测试

原文链接:https://rumenz.com/rumenbiji/linux-secret-key-login.html
微信公众号:入门小站

  • 回复【1001】获取 linux常用命令速查手册
  • 回复【10010】获取 阿里云ECS运维Linux系统诊断
  • 回复【10012】获取 Linux学习笔记【强悍总结值得一看】
  • 回复【10013】获取 shell简明教程

以上是关于linux之秘钥登录的主要内容,如果未能解决你的问题,请参考以下文章

3.以太坊之秘钥文件

linux 免密登录- 秘钥登录

Linux 秘钥对登录远程主机

linux系统下ssh免秘钥登录

linux服务器使用ssh秘钥登录

Linux远程ssh免密码,秘钥登录