[ubuntu] ssh登录docker

Ray Zhang



docker run -d your_image:tag /usr/sbin/sshd -p 12345 -D
  • -d 是docker的指令,后台运行
  • /usr/sbin/sshd -p 12345 -D 容器运行的指令,开启12345端口的ssh连接

Do not detach and become daemon. This is often used when sshd is run using systemd. This allows easier monitoring of the process in such environments. Without this option, the SSH server forks and detaches from terminal, making itself a background daemon process. The latter has been the traditional way to run the SSH server until recently. Many embedded systems would still use the latter.


$ ssh root@{ip got above} -p 12345



# install ssh
$ apt-get install openssh-client
$ apt-get install openssh-server

# start ssh service
$ /etc/init.d/ssh start
 * Starting OpenBSD Secure Shell server sshd        [ OK ] 

# enable root login
$ vim /etc/ssh/sshd_config

#------------ in file sshd_config -------------#
# "PermitRootLogin yes" needs adding as below
# 像下面一样加上"PermitRootLogin yes"
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#---------- end of file sshd_config -----------#

# restart service
$ service ssh restart
* Restarting OpenBSD Secure Shell server sshd            [ OK ] 

# set password of user root
$ passwd root

# add port to ssh
$ /usr/sbin/sshd -p 12345

# checkout ip
$ apt-get install net-tools
$ ifconfig


$ ssh root@{ip got above} -p 12345
阅读 177
1 声望
2 粉丝
0 条评论
1 声望
2 粉丝