Linux SSH 免密钥登录配置

文章目录
  • 概述
  • 配置免密登录
  • 概述

    业务场景中经常需要进行跨服务器的操作,即从一台服务器上登录到另外一台服务器,默认情况下,SSH远程登录时需要输入远程服务器密码。当需要在可信任的服务器之间进行频繁或自动化的操作时,输入密码就会带来不便,本文介绍如何实现SSH远程免密登录。

    配置免密登录

    • 在本地服务器上运行命令,生成公钥、私钥
    ssh-keygen -t rsa

    执行该命令后,系统提示时直接三次回车即可(一般按默认值)

    [cenots@nnkin ~]$ ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/nnkin/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /home/nnkin/.ssh/id_rsa.
    Your public key has been saved in /home/nnkin/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:Ct6HIbAfypJpr/VLzxOeWX4WngQPUaSrJTguPN23Eh4 centos@nnkin
    The key's randomart image is:
    +---[RSA 2048]----+
    |          oo     |
    |         ..      |
    |  .      ..      |
    |   o  .  o.      |
    |  . +o..So+      |
    | +.+o=oE+. +     |
    |+.o=o+*oX.o o    |
    |..o = oO...=     |
    | ... o.oo.o      |
    +----[SHA256]-----+
    [cenots@nnkin ~]$
    • 公钥储存在 /root/.ssh/id_rsa.pub
    • 私钥储存在 /root/.ssh/id_rsa
    [cenots@nnkin ~]$ cd ~/.ssh/
    [cenots@nnkin .ssh]$ ls
    id_rsa  id_rsa.pub  known_hosts
    
    
    • 在本地服务器上运行命令,拷贝公钥至远程服务器
    ssh-copy-id -i /root/.ssh/id_rsa.pub root@<IP_ADDRESS>

    执行此命令需要输入远程服务器密码

    • 在本地服务器上运行命令,测试ssh免密登录远程服务器
    ssh <IP_ADDRESS>

    此时就可以直接免密登录远程服务器进行操作了。

    0

    1. This post has no comment yet

    发表回复

    您的邮箱地址不会被公开。 必填项已用 * 标注

    使用DLVM本地部署DeepSeek(补充)
    使用DLVM本地部署DeepSeek(补充)
    Linux 6 张图
    Error response from daemon: Get “https://registry-1.docker.io/v2/”: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
    Error response from daemon: Get “https://registry-1.docker.io/v2/”: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
    Linux 2 张图
    MySQL 30周年庆 OCP 认证免费
    MySQL 30周年庆 OCP 认证免费
    Linux 5 张图
    使用Kubeadm在Ubuntu 20.04中部署Kubernetes
    使用Kubeadm在Ubuntu 20.04中部署Kubernetes
    Linux 24 张图
    在Linux上安装和配置Squid代理服务器
    在Linux上安装和配置Squid代理服务器
    Linux 10 张图
    Wifipumpkin3 安装记录
    Wifipumpkin3 安装记录
    Linux 1 张图
    © 2025 诺诺博客如有侵权请联系删除 | 网站地图 | 百度统计 | 又拍云CDN加速
    为了获得更好的浏览效果 建议您使用IE8.0及以上版本浏览器登陆本站点 · 服务器托管于腾讯云
    📢 小站正在装修中,如页面异常请包涵!