linux之秘钥登录

枕上诗书闲处好,门前风景雨来佳。这篇文章主要讲述linux之秘钥登录相关的知识,希望能为你提供帮助。
两台主机(服务器)秘钥登录流程图
【linux之秘钥登录】

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 root1675 May7 21:39 id_rsa //私钥 -rw-r--r--1 root root389 May7 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之秘钥登录

文章图片


    推荐阅读