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

相关文章

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.创建区域

Linux上设置Ollama服务配置(常用环境变量)

《Linux上设置Ollama服务配置(常用环境变量)》本文主要介绍了Linux上设置Ollama服务配置(常用环境变量),Ollama提供了多种环境变量供配置,如调试模式、模型目录等,下面就来介绍一... 目录在 linux 上设置环境变量配置 OllamPOgxSRJfa手动安装安装特定版本查看日志在

最新Spring Security实战教程之表单登录定制到处理逻辑的深度改造(最新推荐)

《最新SpringSecurity实战教程之表单登录定制到处理逻辑的深度改造(最新推荐)》本章节介绍了如何通过SpringSecurity实现从配置自定义登录页面、表单登录处理逻辑的配置,并简单模拟... 目录前言改造准备开始登录页改造自定义用户名密码登陆成功失败跳转问题自定义登出前后端分离适配方案结语前言

Centos环境下Tomcat虚拟主机配置详细教程

《Centos环境下Tomcat虚拟主机配置详细教程》这篇文章主要讲的是在CentOS系统上,如何一步步配置Tomcat的虚拟主机,内容很简单,从目录准备到配置文件修改,再到重启和测试,手把手带你搞定... 目录1. 准备虚拟主机的目录和内容创建目录添加测试文件2. 修改 Tomcat 的 server.X

Ubuntu中Nginx虚拟主机设置的项目实践

《Ubuntu中Nginx虚拟主机设置的项目实践》通过配置虚拟主机,可以在同一台服务器上运行多个独立的网站,本文主要介绍了Ubuntu中Nginx虚拟主机设置的项目实践,具有一定的参考价值,感兴趣的可... 目录简介安装 Nginx创建虚拟主机1. 创建网站目录2. 创建默认索引文件3. 配置 Nginx4

如何关闭 Mac 触发角功能或设置修饰键? mac电脑防止误触设置技巧

《如何关闭Mac触发角功能或设置修饰键?mac电脑防止误触设置技巧》从Windows换到iOS大半年来,触发角是我觉得值得吹爆的MacBook效率神器,成为一大说服理由,下面我们就来看看mac电... MAC 的「触发角」功能虽然提高了效率,但过于灵敏也让不少用户感到头疼。特别是在关键时刻,一不小心就可能触

Nginx配置系统服务&设置环境变量方式

《Nginx配置系统服务&设置环境变量方式》本文介绍了如何将Nginx配置为系统服务并设置环境变量,以便更方便地对Nginx进行操作,通过配置系统服务,可以使用系统命令来启动、停止或重新加载Nginx... 目录1.Nginx操作问题2.配置系统服android务3.设置环境变量总结1.Nginx操作问题