Skip to content
Eternal Center

Eternal Center

  • Single-Node (单节点)
    • System (系统)
    • Service (服务)
    • Database (数据库)
    • Container (容器)
    • Virtualization (虚拟化)
  • Multi-Node (多节点)
    • Cluster (集群)
    • Big Data (大数据)
    • Cloud Computing (云计算)
    • Batch Processing (批量处理)
  • Approach (方式方法)
    • Languages (语言)
    • Ideas (思路)
    • Programing (编程)
    • Project (项目)
  • Eternity (永恒)
    • News (消息)
    • Creations (创作)
    • Classics (经典)
    • Legends (传说)
    • Chronicle (编年史)
    • FNIOS (宇宙公民开源学院)
Posted on May 9, 2020November 22, 2024 by Mingyu Zhu

[步骤] Linux 无密码 SSH 的实现 (通过复杂 SSH 公私密钥实现)

  • 步骤一:生成复杂的 SSH 密钥
    • 1.1 生成复杂的 SSH 密钥
    • 1.2 将生成的复杂 SSH 密钥移动到指定位置
    • 1.3 给部署好的复杂 SSH 密钥设置权限
  • 步骤二:将复杂的 SSH 公钥拷贝到目标服务器
  • 步骤三:指定复杂 SSH 密钥登录目标服务器
  • 步骤四:在目标服务器上设置只能使用密钥登录
    • 4.1 修改 /etc/ssh/sshd_conf 配置文件
    • 4.2 让修改的 /etc/ssh/sshd_conf 配置文件生效
  • 补充一:修改复杂 SSH 密钥密码的方法
  • 补充二:显示已生成的 SSH 密钥的加密方式

步骤一:生成复杂的 SSH 密钥

1.1 生成复杂的 SSH 密钥

# ssh-keygen -b 4096 -t rsa -C "<content>" -f "<public private key name>"

(注意:在生成复杂 SSH 密钥的时候最好也设置它的使用密码)

1.2 将生成的复杂 SSH 密钥移动到指定位置

# mv <public private key name>* ~/.ssh/

1.3 给部署好的复杂 SSH 密钥设置权限

# chmod -R 600 ~/.ssh/<public private key name>*

步骤二:将复杂的 SSH 公钥拷贝到目标服务器

# ssh-copy-id -i ~/.ssh/<public private key name>.pub <destination IP address>

步骤三:指定复杂 SSH 密钥登录目标服务器

# ssh -i ~/.ssh/<public private key name> <destination IP address>

步骤四:在目标服务器上设置只能使用密钥登录

4.1 修改 /etc/ssh/sshd_conf 配置文件

如果是 Rocky Linux & RHEL:

# vim /etc/ssh/sshd_conf

将其中的:

......
# PasswordAuthentication yes
......

修改为:

......
PasswordAuthentication no
......

如果是 openSUSE & SLES:

# vim /etc/ssh/sshd_conf

将其中的:

......
# PasswordAuthentication yes
......
# ChallengeResponseAuthentication yes
......

修改为:

......
PasswordAuthentication no
......
ChallengeResponseAuthentication no
......

4.2 让修改的 /etc/ssh/sshd_conf 配置文件生效

# systemctl restart sshd

补充一:修改复杂 SSH 密钥密码的方法

# ssh-keygen -p -f ~/.ssh/<public private key name>

(补充:无密码的 SSH 密钥也能通过此方法设置密码)

补充二:显示已生成的 SSH 密钥的加密方式

# ssh-keygen -l -f ~/.ssh/<public private key name>
CategoriesChinese Post (中文帖子), System (系统), System Login Security (系统登录安全), System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志), System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件), System Port Security (系统端口安全), System Security (系统安全), System Setting (系统设置), System Setting Other Steps (系统设置其它步骤), System Setting Others (系统设置其它)

Post navigation

Previous PostPrevious [实验] Linux Django 项目的制作 (PyCharm 版)
Next PostNext [命令] Linux 命令 passwd (管理密码)

Aspiration (愿景):

Everyone can achieve self-achievement and self-happiness fairly

每个人都能公平地实现自我成就和自我幸福

Logo (徽标):

Additional Information (其他信息):

About     Manual     Clone     Contact
Disclaimer     Friendly Links     Donation

关于     手册     克隆     联系
免责声明     友情链接     捐赠

Search Inside Website (站内搜索)

Search Outside Website (站外搜索):

Google         Wikipedia         Bing

Eternal URL (永恒网址):

https://eternity.eternalcenter.com Will be last access method / 将是最后的访问方式

Proudly powered by LNMP Proudly powered by WordPress