Ubuntu设置SSH免密登录(不同于CentOS)

2024-02-23 10:08

本文主要是介绍Ubuntu设置SSH免密登录(不同于CentOS),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录(?)[-]

  1. Ubuntu设置SSH免密登录不同于CentOS
    1. 遇到的坑
    2. 解决办法
      1. 1 先删除之前的ssh
      2. 2 生成免密
      3. 3 免密登录本机
    3. 集群免密登录
      1. 1 第2个节点生成免密
      2. 2 第3个节点生成免密
      3. 3 分发公钥
      4. 4 集群免密登录

Ubuntu设置SSH免密登录(不同于CentOS)

1.遇到的坑

之前一直在CentOS系统进行Hadoop开发,SSH免密登录配置过N次,今天在Ubuntu平台下设置免密登录遇到了坑:

kylin@uk0:~$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
Generating public/private dsa key pair.
Created directory '/home/kylin/.ssh'.
Your identification has been saved in /home/kylin/.ssh/id_dsa.
Your public key has been saved in /home/kylin/.ssh/id_dsa.pub.
The key fingerprint is:
SHA256:Kp2T562S8CP1Ui7LJMDlFAMBqujJ8HyrhvsAfWHu8X8 kylin@uk0
The key's randomart image is:
+---[DSA 1024]----+
|..ooo            |
|.    o           |
|.   =            |
|oo * .           |
|= + =   S        |
|=o.+.+.+.        |
|.=o =+O=.        |
|.....*B=o.E      |
|.+o...o*+o.      |
+----[SHA256]-----+
kylin@uk0:~$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
kylin@uk0:~$ chmod 0600 ~/.ssh/authorized_keys
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

免密登录本机时,竟然需要输入密码!?

kylin@uk0:~$ ssh uk0
The authenticity of host 'uk0 (192.168.1.160)' can't be established.
ECDSA key fingerprint is SHA256:dOKnH/ES8JcWzGkdRwRzYGzDkBE8y7cJpRx/DNHhGVc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'uk0,192.168.1.160' (ECDSA) to the list of known hosts.
kylin@uk0's password: 
Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-22-generic x86_64)* Documentation:  https://help.ubuntu.com* Management:     https://landscape.canonical.com* Support:        https://ubuntu.com/advantage279 个可升级软件包。
107 个安全更新。Last login: Fri Mar  3 15:20:29 2017 from 192.168.1.81
kylin@uk0:~$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

2.解决办法

2.1 先删除之前的.ssh

kylin@uk0:~$ rm -rf .ssh
  • 1
  • 2

2.2 生成免密

与CentOS不同,需要使用ssh-keygen -t rsa命令生成,一直按Enter,按到最后。

kylin@uk0:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/kylin/.ssh/id_rsa): 
Created directory '/home/kylin/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/kylin/.ssh/id_rsa.
Your public key has been saved in /home/kylin/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Onr5G6x8pcsmksQNuMECb2oOu7lKoOzGPh0+x6y0Pj4 kylin@uk0
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|.                |
|.o .             |
|. * .            |
|.+ + o  S        |
|*...o .o  .      |
|*+oo+.o.oo       |
|+*.E+*+++.       |
|O=+=Boo==o       |
+----[SHA256]-----+
kylin@uk0:~$ cat .ssh/id_rsa.pub >> .ssh/authorized_keys
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

2.3 免密登录本机

kylin@uk0:~$ ssh uk0
The authenticity of host 'uk0 (192.168.1.160)' can't be established.
ECDSA key fingerprint is SHA256:dOKnH/ES8JcWzGkdRwRzYGzDkBE8y7cJpRx/DNHhGVc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'uk0,192.168.1.160' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-22-generic x86_64)
Last login: Fri Mar  3 16:11:16 2017 from 192.168.1.160
kylin@uk0:~$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3 集群免密登录

3.1 第2个节点生成免密

kylin@uk1:~$ rm -rf .ssh
kylin@uk1:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/kylin/.ssh/id_rsa): 
Created directory '/home/kylin/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/kylin/.ssh/id_rsa.
Your public key has been saved in /home/kylin/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pGAXPlmDGitJNPmUGXcS2ZZrQw581nTH7Y7zzUTU1Fs kylin@uk1
The key's randomart image is:
+---[RSA 2048]----+
| .o..===++. ...o+|
|  o.=o=*B... .. E|
| . +o+=B..     oo|
|  o.+o +=      .o|
|   .  ..S.     + |
|              o o|
|               =.|
|                +|
|                 |
+----[SHA256]-----+
kylin@uk1:~$ cat .ssh/id_rsa.pub >> .ssh/authorized_keys
kylin@uk1:~$ ssh uk1
The authenticity of host 'uk1 (192.168.1.161)' can't be established.
ECDSA key fingerprint is SHA256:dOKnH/ES8JcWzGkdRwRzYGzDkBE8y7cJpRx/DNHhGVc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'uk1,192.168.1.161' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-22-generic x86_64)
Last login: Fri Mar  3 16:23:19 2017 from 192.168.1.161
kylin@uk1:~$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

3.2 第3个节点生成免密

kylin@uk2:~$ rm -rf .ssh
kylin@uk2:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/kylin/.ssh/id_rsa): 
Created directory '/home/kylin/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/kylin/.ssh/id_rsa.
Your public key has been saved in /home/kylin/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:/chD0D2CNj5iryn7Jue5lLxXzq3RAjwtG7Jrasz0KYk kylin@uk2
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|         o .     |
|        = o o    |
|       + = . .   |
|      + S +      |
|    .o * X.+     |
|   = o=.o+*.o    |
|  E O.**. o+.    |
|   .o%Xo  ..     |
+----[SHA256]-----+
kylin@uk2:~$ cat .ssh/id_rsa.pub >> .ssh/authorized_keys
kylin@uk2:~$ ssh uk2
The authenticity of host 'uk2 (192.168.1.162)' can't be established.
ECDSA key fingerprint is SHA256:dOKnH/ES8JcWzGkdRwRzYGzDkBE8y7cJpRx/DNHhGVc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'uk2,192.168.1.162' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-22-generic x86_64)* Documentation:  https://help.ubuntu.com* Management:     https://landscape.canonical.com* Support:        https://ubuntu.com/advantage
Last login: Fri Mar  3 16:03:44 2017 from 192.168.1.160
kylin@uk2:~$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

3.3 分发公钥

kylin@uk1:~$ cat ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCisjV42WGpF64EffoSVB1fxXGqwE/9uYuDgwHzfXK47c54vLLtGfpKqzzXfDoTLWtR1P/W5stGGqLxarP27Nz7ujd4rQKt3t8JXSnlQIIhkojo4JGcF3JDAm9V5nGaqpMse65tbdK24+tkmVolwfZJTOZi9O1bctzBaZOapzu498/2Tlzy1jSToQmDlT0zsAhbs1ipF1aBRLzjnU0i9gXhF2dW2pQvvJk1TBMx8A1xIPAviQ43NhUoNsUhZYeRIQ9XPe293/48tId3a3M4OvQ26tHLEiG8sDRl3w5Nc2NXybs4RVydAmiCS4kh/SgALgtpq/HF3SpWlbYXl4S5j1cb kylin@uk1
  • 1
  • 2
kylin@uk2:~$ cat ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFdBdhmycLgyu4D/i3cneY4ERwnj/a2Q8JFHLizAg66qul7mykOIziI9IKRfE8nS4/vsOLTtUiTMsNqvpuWWGoibRXmxnrf19IwfyQ/YIuwllQ3Bm439Gyn+s2frK8i5Sw5wyCw+FiL4BS8WpPr4qWHXHajBI2VP4SNZuLdPlvCoZXYawWVOvlk8skt5WuXKpEjNEku+4w1Dyq3pT76iDBGxGk/JYzZRvyvUvQdBcYNgWjZNcva8HWYXpckmuoHh8VmeRDRhj1KGADsypw0L1jM7HG2hnGulqb3Xil2KJdMiPzp9uGJskSfZbLI6v7QLkQqOIpSAtIFZd+IxHwxIaF kylin@uk2
  • 1
  • 2

合并公钥

kylin@uk0:~$ vi ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCnAW4j0oGFL36qoruUOkUaf5xIy7h4BrrGxvVnRpZAIGnCGwBt3OKLUrsWVQONQl6dr8f/TFbcAdAulPkn2/NmtjQLz6cMC3KiXlwk8x5Wz5c+cZ/TmkMEFRpxh48/0rfFHdZvLHcXx/WZzU0tIEjspZHxTq+oaZ3jgro7VweKGva0WVFuEJczUccMQOj+cRnLrt1Jy5ipaQHWtk2MYhfgfk168Bub6mEyLqbrUHB4zx+u+ukOg0skjBO2Kybn8OJABkdiA9V+d4UTFeK0XoywzcUsSGT0Tro6lUJ5i8haiWcPJutR7kXosL2aoU2480LUtQLqo7yJ1mT+FUE2uuMR kylin@uk0
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCisjV42WGpF64EffoSVB1fxXGqwE/9uYuDgwHzfXK47c54vLLtGfpKqzzXfDoTLWtR1P/W5stGGqLxarP27Nz7ujd4rQKt3t8JXSnlQIIhkojo4JGcF3JDAm9V5nGaqpMse65tbdK24+tkmVolwfZJTOZi9O1bctzBaZOapzu498/2Tlzy1jSToQmDlT0zsAhbs1ipF1aBRLzjnU0i9gXhF2dW2pQvvJk1TBMx8A1xIPAviQ43NhUoNsUhZYeRIQ9XPe293/48tId3a3M4OvQ26tHLEiG8sDRl3w5Nc2NXybs4RVydAmiCS4kh/SgALgtpq/HF3SpWlbYXl4S5j1cb kylin@uk1
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFdBdhmycLgyu4D/i3cneY4ERwnj/a2Q8JFHLizAg66qul7mykOIziI9IKRfE8nS4/vsOLTtUiTMsNqvpuWWGoibRXmxnrf19IwfyQ/YIuwllQ3Bm439Gyn+s2frK8i5Sw5wyCw+FiL4BS8WpPr4qWHXHajBI2VP4SNZuLdPlvCoZXYawWVOvlk8skt5WuXKpEjNEku+4w1Dyq3pT76iDBGxGk/JYzZRvyvUvQdBcYNgWjZNcva8HWYXpckmuoHh8VmeRDRhj1KGADsypw0L1jM7HG2hnGulqb3Xil2KJdMiPzp9uGJskSfZbLI6v7QLkQqOIpSAtIFZd+IxHwxIaF kylin@uk2
  • 1
  • 2
  • 3
  • 4

分发公钥

kylin@uk0:~$ scp .ssh/authorized_keys kylin@192.168.1.161:/home/kylin/.ssh
The authenticity of host '192.168.1.161 (192.168.1.161)' can't be established.
ECDSA key fingerprint is SHA256:dOKnH/ES8JcWzGkdRwRzYGzDkBE8y7cJpRx/DNHhGVc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.161' (ECDSA) to the list of known hosts.
kylin@192.168.1.161's password: 
authorized_keys                                                                                                                           100% 1173   692.4KB/s   00:00    
kylin@uk0:~$ scp .ssh/authorized_keys kylin@192.168.1.162:/home/kylin/.ssh
The authenticity of host '192.168.1.162 (192.168.1.162)' can't be established.
ECDSA key fingerprint is SHA256:dOKnH/ES8JcWzGkdRwRzYGzDkBE8y7cJpRx/DNHhGVc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.162' (ECDSA) to the list of known hosts.
kylin@192.168.1.162's password: 
authorized_keys                                                                                                                           100% 1173     1.1MB/s   00:00    
kylin@uk0:~$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

3.4 集群免密登录

kylin@uk0:~$ ssh uk1
The authenticity of host 'uk1 (192.168.1.161)' can't be established.
ECDSA key fingerprint is SHA256:dOKnH/ES8JcWzGkdRwRzYGzDkBE8y7cJpRx/DNHhGVc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'uk1' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-22-generic x86_64)* Documentation:  https://help.ubuntu.com* Management:     https://landscape.canonical.com* Support:        https://ubuntu.com/advantage279 个可升级软件包。
107 个安全更新。Last login: Fri Mar  3 16:24:21 2017 from 192.168.1.161
kylin@uk1:~$ 
kylin@uk1:~$ ssh uk2
The authenticity of host 'uk2 (192.168.1.162)' can't be established.
ECDSA key fingerprint is SHA256:dOKnH/ES8JcWzGkdRwRzYGzDkBE8y7cJpRx/DNHhGVc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'uk2,192.168.1.162' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-22-generic x86_64)* Documentation:  https://help.ubuntu.com* Management:     https://landscape.canonical.com* Support:        https://ubuntu.com/advantage279 个可升级软件包。
107 个安全更新。Last login: Fri Mar  3 16:25:05 2017 from 192.168.1.162

这篇关于Ubuntu设置SSH免密登录(不同于CentOS)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/738265

相关文章

Ubuntu 24.04启用root图形登录的操作流程

《Ubuntu24.04启用root图形登录的操作流程》Ubuntu默认禁用root账户的图形与SSH登录,这是为了安全,但在某些场景你可能需要直接用root登录GNOME桌面,本文以Ubuntu2... 目录一、前言二、准备工作三、设置 root 密码四、启用图形界面 root 登录1. 修改 GDM 配

nginx 负载均衡配置及如何解决重复登录问题

《nginx负载均衡配置及如何解决重复登录问题》文章详解Nginx源码安装与Docker部署,介绍四层/七层代理区别及负载均衡策略,通过ip_hash解决重复登录问题,对nginx负载均衡配置及如何... 目录一:源码安装:1.配置编译参数2.编译3.编译安装 二,四层代理和七层代理区别1.二者混合使用举例

如何在Ubuntu 24.04上部署Zabbix 7.0对服务器进行监控

《如何在Ubuntu24.04上部署Zabbix7.0对服务器进行监控》在Ubuntu24.04上部署Zabbix7.0监控阿里云ECS服务器,需配置MariaDB数据库、开放10050/1005... 目录软硬件信息部署步骤步骤 1:安装并配置mariadb步骤 2:安装Zabbix 7.0 Server

Ubuntu如何分配​​未使用的空间

《Ubuntu如何分配​​未使用的空间》Ubuntu磁盘空间不足,实际未分配空间8.2G因LVM卷组名称格式差异(双破折号误写)导致无法扩展,确认正确卷组名后,使用lvextend和resize2fs... 目录1:原因2:操作3:报错5:解决问题:确认卷组名称​6:再次操作7:验证扩展是否成功8:问题已解

linux hostname设置全过程

《linuxhostname设置全过程》:本文主要介绍linuxhostname设置全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录查询hostname设置步骤其它相关点hostid/etc/hostsEDChina编程A工具license破解注意事项总结以RHE

Python设置Cookie永不超时的详细指南

《Python设置Cookie永不超时的详细指南》Cookie是一种存储在用户浏览器中的小型数据片段,用于记录用户的登录状态、偏好设置等信息,下面小编就来和大家详细讲讲Python如何设置Cookie... 目录一、Cookie的作用与重要性二、Cookie过期的原因三、实现Cookie永不超时的方法(一)

Linux中SSH服务配置的全面指南

《Linux中SSH服务配置的全面指南》作为网络安全工程师,SSH(SecureShell)服务的安全配置是我们日常工作中不可忽视的重要环节,本文将从基础配置到高级安全加固,全面解析SSH服务的各项参... 目录概述基础配置详解端口与监听设置主机密钥配置认证机制强化禁用密码认证禁止root直接登录实现双因素

CSS3打造的现代交互式登录界面详细实现过程

《CSS3打造的现代交互式登录界面详细实现过程》本文介绍CSS3和jQuery在登录界面设计中的应用,涵盖动画、选择器、自定义字体及盒模型技术,提升界面美观与交互性,同时优化性能和可访问性,感兴趣的朋... 目录1. css3用户登录界面设计概述1.1 用户界面设计的重要性1.2 CSS3的新特性与优势1.

Qt 设置软件版本信息的实现

《Qt设置软件版本信息的实现》本文介绍了Qt项目中设置版本信息的三种常用方法,包括.pro文件和version.rc配置、CMakeLists.txt与version.h.in结合,具有一定的参考... 目录在运行程序期间设置版本信息可以参考VS在 QT 中设置软件版本信息的几种方法方法一:通过 .pro

PostgreSQL 默认隔离级别的设置

《PostgreSQL默认隔离级别的设置》PostgreSQL的默认事务隔离级别是读已提交,这是其事务处理系统的基础行为模式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录一 默认隔离级别概述1.1 默认设置1.2 各版本一致性二 读已提交的特性2.1 行为特征2.2