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