docker中开启sshd

    首先在docker中安装openssh-server,安装完毕后切换到openssh-server的安装目录/etc/ssh下面。运行ssh-keygen生成对应的密钥。先看看sshd的配置文件sshd_config,里面有如下内容:
HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
    有rsa,dsa,ecdsa,ed25519的加密方式,根据这几种加密方式来生成对应的密钥对。
[root@655f62a4ed82 ssh]# ssh-keygen -t rsa  //生成rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
0e:fa:07:36:bb:87:c1:60:14:be:41:41:01:1b:4b:bc root@655f62a4ed82
The key's randomart image is:
+--[ RSA 2048]----+
| .+o*+           |
| ..*.            |
|  ooo            |
|  E oo           |
|   ..o. S        |
|     .*o         |
|    .. *.        |
|     .o o        |
|      o+         |
+-----------------+
[root@655f62a4ed82 ssh]# ssh-keygen -t dsa //生成dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
ee:8c:db:a8:24:68:0d:33:79:eb:09:33:ed:74:c3:66 root@655f62a4ed82
The key's randomart image is:
+--[ DSA 1024]----+
|                 |
|                 |
|                 |
|  .              |
| = .    S        |
| .B o  .         |
|.=.=.E  .        |
|. Bo= .*         |
|   +..+.+        |
+-----------------+
[root@655f62a4ed82 ssh]# ssh-keygen -t ecdsa //生成ecdsa
Generating public/private ecdsa key pair.
Enter file in which to save the key (/root/.ssh/id_ecdsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_ecdsa.
Your public key has been saved in /root/.ssh/id_ecdsa.pub.
The key fingerprint is:
84:74:de:d1:e4:98:a1:5c:27:25:8e:b7:d6:27:fd:c9 root@655f62a4ed82
The key's randomart image is:
+--[ECDSA  256]---+
|      . . *++    |
|     . = * X.    |
|      . * * .    |
|       . . o .   |
|        S o o o  |
|         .   o...|
|               E.|
|                 |
|                 |
+-----------------+
[root@655f62a4ed82 ssh]# ssh-keygen -t ed25519
Generating public/private ed25519 key pair.
Enter file in which to save the key (/root/.ssh/id_ed25519): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_ed25519.
Your public key has been saved in /root/.ssh/id_ed25519.pub.
The key fingerprint is:
d8:40:95:1f:07:96:8a:83:7f:af:19:01:3b:b4:79:91 root@655f62a4ed82
The key's randomart image is:
+--[ED25519  256--+
|      ....oo     |
|     .  .oo .    |
|     .+.Eo o     |
|    ..oO...      |
|     .*.S        |
|      .o..       |
|       ...       |
|         o.      |
|        o.       |
+-----------------+
[root@655f62a4ed82 ssh]# cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys 
    密钥对生成完毕后,需要修改sshd_config中上述文件所在的位置的。
HostKey /root/.ssh/id_rsa
HostKey /root/.ssh/id_dsa
HostKey /root/.ssh/id_ecdsa
HostKey /root/.ssh/id_ed25519
    运行/usr/sbin/sshd,查看22端口号是否开启,开启说明启动成功。
[root@655f62a4ed82 ssh]# /usr/sbin/sshd
[root@655f62a4ed82 ssh]# lsof -i:22
COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd     37 root    3u  IPv4 250907      0t0  TCP *:ssh (LISTEN)
sshd     37 root    4u  IPv6 250909      0t0  TCP *:ssh (LISTEN)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值