docker中开启sshd

来源:互联网 发布:java编程思想电子书 编辑:程序博客网 时间:2024/06/05 18:45
    首先在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_keyHostKey /etc/ssh/ssh_host_ecdsa_keyHostKey /etc/ssh/ssh_host_ed25519_key
    有rsa,dsa,ecdsa,ed25519的加密方式,根据这几种加密方式来生成对应的密钥对。
[root@655f62a4ed82 ssh]# ssh-keygen -t rsa  //生成rsaGenerating 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@655f62a4ed82The key's randomart image is:+--[ RSA 2048]----+| .+o*+           || ..*.            ||  ooo            ||  E oo           ||   ..o. S        ||     .*o         ||    .. *.        ||     .o o        ||      o+         |+-----------------+[root@655f62a4ed82 ssh]# ssh-keygen -t dsa //生成dsaGenerating 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@655f62a4ed82The key's randomart image is:+--[ DSA 1024]----+|                 ||                 ||                 ||  .              || = .    S        || .B o  .         ||.=.=.E  .        ||. Bo= .*         ||   +..+.+        |+-----------------+[root@655f62a4ed82 ssh]# ssh-keygen -t ecdsa //生成ecdsaGenerating 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@655f62a4ed82The key's randomart image is:+--[ECDSA  256]---+|      . . *++    ||     . = * X.    ||      . * * .    ||       . . o .   ||        S o o o  ||         .   o...||               E.||                 ||                 |+-----------------+[root@655f62a4ed82 ssh]# ssh-keygen -t ed25519Generating 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@655f62a4ed82The 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_rsaHostKey /root/.ssh/id_dsaHostKey /root/.ssh/id_ecdsaHostKey /root/.ssh/id_ed25519
    运行/usr/sbin/sshd,查看22端口号是否开启,开启说明启动成功。
[root@655f62a4ed82 ssh]# /usr/sbin/sshd[root@655f62a4ed82 ssh]# lsof -i:22COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEsshd     37 root    3u  IPv4 250907      0t0  TCP *:ssh (LISTEN)sshd     37 root    4u  IPv6 250909      0t0  TCP *:ssh (LISTEN)
0 0
原创粉丝点击