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

相关文章

CentOS7更改默认SSH端口与配置指南

《CentOS7更改默认SSH端口与配置指南》SSH是Linux服务器远程管理的核心工具,其默认监听端口为22,由于端口22众所周知,这也使得服务器容易受到自动化扫描和暴力破解攻击,本文将系统性地介绍... 目录引言为什么要更改 SSH 默认端口?步骤详解:如何更改 Centos 7 的 SSH 默认端口1

kali linux 无法登录root的问题及解决方法

《kalilinux无法登录root的问题及解决方法》:本文主要介绍kalilinux无法登录root的问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,... 目录kali linux 无法登录root1、问题描述1.1、本地登录root1.2、ssh远程登录root2、

C#TextBox设置提示文本方式(SetHintText)

《C#TextBox设置提示文本方式(SetHintText)》:本文主要介绍C#TextBox设置提示文本方式(SetHintText),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录C#TextBox设置提示文本效果展示核心代码总结C#TextBox设置提示文本效果展示核心代

Pyserial设置缓冲区大小失败的问题解决

《Pyserial设置缓冲区大小失败的问题解决》本文主要介绍了Pyserial设置缓冲区大小失败的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录问题描述原因分析解决方案问题描述使用set_buffer_size()设置缓冲区大小后,buf

Feign Client超时时间设置不生效的解决方法

《FeignClient超时时间设置不生效的解决方法》这篇文章主要为大家详细介绍了FeignClient超时时间设置不生效的原因与解决方法,具有一定的的参考价值,希望对大家有一定的帮助... 在使用Feign Client时,可以通过两种方式来设置超时时间:1.针对整个Feign Client设置超时时间

Ubuntu中远程连接Mysql数据库的详细图文教程

《Ubuntu中远程连接Mysql数据库的详细图文教程》Ubuntu是一个以桌面应用为主的Linux发行版操作系统,这篇文章主要为大家详细介绍了Ubuntu中远程连接Mysql数据库的详细图文教程,有... 目录1、版本2、检查有没有mysql2.1 查询是否安装了Mysql包2.2 查看Mysql版本2.

springboot security验证码的登录实例

《springbootsecurity验证码的登录实例》:本文主要介绍springbootsecurity验证码的登录实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录前言代码示例引入依赖定义验证码生成器定义获取验证码及认证接口测试获取验证码登录总结前言在spring

新特性抢先看! Ubuntu 25.04 Beta 发布:Linux 6.14 内核

《新特性抢先看!Ubuntu25.04Beta发布:Linux6.14内核》Canonical公司近日发布了Ubuntu25.04Beta版,这一版本被赋予了一个活泼的代号——“Plu... Canonical 昨日(3 月 27 日)放出了 Beta 版 Ubuntu 25.04 系统镜像,代号“Pluc

PyCharm如何设置新建文件默认为LF换行符

《PyCharm如何设置新建文件默认为LF换行符》:本文主要介绍PyCharm如何设置新建文件默认为LF换行符问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录PyCharm设置新建文件默认为LF换行符设置换行符修改换行符总结PyCharm设置新建文件默认为LF

CentOS 7部署主域名服务器 DNS的方法

《CentOS7部署主域名服务器DNS的方法》文章详细介绍了在CentOS7上部署主域名服务器DNS的步骤,包括安装BIND服务、配置DNS服务、添加域名区域、创建区域文件、配置反向解析、检查配置... 目录1. 安装 BIND 服务和工具2.  配置 BIND 服务3 . 添加你的域名区域配置4.创建区域