docker安装ssh

文章讲述了在Linux系统中如何下载并安装OpenSSH,遇到无法加载主机密钥的问题后,通过执行ssh-keygen命令生成RSA、ECDSA和ED25519类型的主机密钥,并解决了相关错误,最后重启SSH服务的过程。
摘要由CSDN通过智能技术生成

1.下载ssh

yum install openssh-clients
yum install openssh-server

在这里插入图片描述

2.遇到下面问题

[root@062e2fff4066 sbi/usr/sbin/sshd -D
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
sshd: no hostkeys available -- exiting.

解决办法

#运行以下命令生成 RSA 主机密钥文件:
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key

#运行以下命令生成 ECDSA 主机密钥文件:
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key

#运行以下命令生成 ED25519 主机密钥文件:
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

结果如下

[root@062e2fff4066 ssh]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Passphrases do not match.  Try again.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
The key fingerprint is:
SHA256:csgNrxab9Yv+KzCoN9xdSQqKLeelVDHU/Y5rRIqNtc0 root@062e2fff4066
The key's randomart image is:
+---[RSA 2048]----+
|     ... .       |
|      o . .      |
|      .o   .     |
|     .o=. o .    |
|   o +=*SO +     |
|  o * *O=.E .    |
|   B +=+ o..     |
|  . *.. o.o.     |
|   . . .o++.     |
+----[SHA256]-----+
[root@062e2fff4066 ssh]# ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
Generating public/private ecdsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /etc/ssh/ssh_host_ecdsa_key.
Your public key has been saved in /etc/ssh/ssh_host_ecdsa_key.pub.
The key fingerprint is:
SHA256:7yXpLn3xYkQ7lfGkHKZxQyTMqEJFYYj7jOhuzTPl8CI root@062e2fff4066
The key's randomart image is:
+---[ECDSA 256]---+
|     . +=. +.oo  |
|    . o.  . +.* .|
|     o   .   * O |
|    . . .   o = .|
|   . + .S  . o   |
|  . o +  . .=    |
| . o =   .+..+   |
|  E * o .o.o+ .  |
| o.. +   o+o .   |
+----[SHA256]-----+
[root@062e2fff4066 ssh]# ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /etc/ssh/ssh_host_ed25519_key.
Your public key has been saved in /etc/ssh/ssh_host_ed25519_key.pub.
The key fingerprint is:
SHA256:r6/stnN/KoO0cGSRLm2LPNyv+i8/AQqxhVRJ9tgZNw4 root@062e2fff4066
The key's randomart image is:
+--[ED25519 256]--+
|   ..++.E.o      |
|    o.o+o* .     |
|     +.o+..      |
|    o . B        |
|     + OSo       |
|      B =..      |
|       = +..     |
|       .*.*   .  |
|      .=O@+=oo   |
+----[SHA256]-----+

在这里插入图片描述

这些命令将在 /etc/ssh/ 路径下生成相应类型的主机密钥文件。
完成之后,再次尝试使用 /usr/sbin/sshd -D 命令启动 SSH 服务器
3.启动ssh

/usr/sbin/sshd -D
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值