V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
css3
V2EX  ›  Docker

启了个 docker 容器, 开启了 ssh 登录,过一天后重新登录,密码不对是咋回事

  •  
  •   css3 · 2021-06-02 15:49:52 +08:00 · 1660 次点击
    这是一个创建于 1302 天前的主题,其中的信息可能已经有所发展或是发生改变。

    docker build 的镜像,ssh 的密码在 build 的时候设置的,非常奇怪是的,容器启动后,正常可以用 ssh 登录,但过一天后,新开窗口重新 ssh 登录,密码就不对了,而且昨天开的已登录窗口还能正常使用。 重启 docke 容器后,又能正常登录,是啥原因啊? 没有人改密码啊,好几天都是这样,都是通过重启容器来解决,不清楚原因是啥

    第 1 条附言  ·  2021-06-02 18:59:12 +08:00
    # Dockerfile
    FROM base_images:latest
    RUN apt-get -y update && apt-get install -y openssh-server openssh-client vim initscripts expect
    
    RUN pip install --upgrade pip 
    RUN sed -i "s/^#PermitRootLogin/PermitRootLogin/g" /etc/ssh/sshd_config
    RUN sed -i "s/prohibit-password/yes/g" /etc/ssh/sshd_config
    RUN echo y | ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ''
    RUN echo y | ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
    RUN echo y | ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N ''
    ARG PASSWORD
    RUN echo "root:${PASSWORD}" | chpasswd
    RUN mkdir /var/run/sshd && chmod 0755 /var/run/sshd
    RUN env | egrep -v "^(HOME=|USER=|MAIL=|LC_ALL=|LS_COLORS=|LANG=|HOSTNAME=|PWD=|TERM=|SHLVL=|LANGUAGE=|_=)" >> /etc/environment
    CMD /usr/sbin/sshd -D && bash
    

    build 指令:

    docker-compose build --build-arg PASSWORD=admin%^&* myproject &&
    docker-compose up -d
    
    11 条回复    2021-06-04 10:22:53 +08:00
    maichael
        1
    maichael  
       2021-06-02 16:12:27 +08:00
    "重启 docker 容器后,又能正常登录",因为 Docker 是无状态的,重启之后会回归刚开始的状态。所以应该是你容器内的某个设置会进行更改密码,可以给下 Dockerfile 关键信息吗
    css3
        2
    css3  
    OP
       2021-06-02 18:59:25 +08:00
    @maichael 贴上了 Dockerfile
    PbCopy111
        3
    PbCopy111  
       2021-06-02 20:33:36 +08:00
    这。。。不是每次生成新密码么。。。。。
    css3
        4
    css3  
    OP
       2021-06-02 22:14:29 +08:00 via iPhone
    @PbCopy111 build 指定的
    killva4624
        5
    killva4624  
       2021-06-03 10:44:21 +08:00
    1 、ssh 的时候具体报错是什么?(可以用 -v 打印出来)
    2 、“重启容器”的具体操作是什么? docker restart xxx 吗,还是每次都重新 build ?看 Dockerfile,如果不重新 build 的话,这个 image 的 sshpassword 是不会变的。
    css3
        6
    css3  
    OP
       2021-06-03 12:03:00 +08:00 via iPhone
    @killva4624 隔天 ssh 登录就是提示密码不正确
    css3
        7
    css3  
    OP
       2021-06-03 12:03:49 +08:00 via iPhone
    @killva4624 肯定不是 build 啊,直接 restart,或者直接 run
    css3
        8
    css3  
    OP
       2021-06-03 13:06:02 +08:00
    @killva4624 Permission denied, please try again.
    css3
        9
    css3  
    OP
       2021-06-03 13:09:49 +08:00
    OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 58: Applying options for *
    debug1: Connecting to 192.168.12.44 [192.168.12.44] port 23.
    debug1: Connection established.
    debug1: permanently_set_uid: 0/0
    debug1: identity file /root/.ssh/id_rsa type 1
    debug1: key_load_public: No such file or directory
    debug1: identity file /root/.ssh/id_rsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /root/.ssh/id_dsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /root/.ssh/id_dsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /root/.ssh/id_ecdsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /root/.ssh/id_ecdsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /root/.ssh/id_ed25519 type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /root/.ssh/id_ed25519-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_7.4
    debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.10
    debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.10 pat OpenSSH* compat 0x04000000
    debug1: Authenticating to 192.168.12.44:23 as 'root'
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: algorithm: [email protected]
    debug1: kex: host key algorithm: ecdsa-sha2-nistp256
    debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
    debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
    debug1: kex: [email protected] need=64 dh_need=64
    debug1: kex: [email protected] need=64 dh_need=64
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug1: Server host key: ecdsa-sha2-nistp256 SHA256:jI6QVVi6Qmi5oZvugssXrHN4Qxjrw9BDNoowxaIZ7so
    debug1: Host '[192.168.12.44]:23' is known and matches the ECDSA host key.
    debug1: Found key in /root/.ssh/known_hosts:4
    debug1: rekey after 134217728 blocks
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug1: rekey after 134217728 blocks
    debug1: SSH2_MSG_EXT_INFO received
    debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: rekey after 134217728 blocks
    debug1: SSH2_MSG_EXT_INFO received
    debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey,password
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /root/.ssh/id_rsa
    debug1: Authentications that can continue: publickey,password
    debug1: Trying private key: /root/.ssh/id_dsa
    debug1: Trying private key: /root/.ssh/id_ecdsa
    debug1: Trying private key: /root/.ssh/id_ed25519
    debug1: Next authentication method: password
    [email protected]'s password:
    debug1: Authentications that can continue: publickey,password
    Permission denied, please try again.
    [email protected]'s password:
    julyclyde
        10
    julyclyde  
       2021-06-03 16:24:14 +08:00
    docker exec 进去看看 sshd 的日志吧
    killva4624
        11
    killva4624  
       2021-06-04 10:22:53 +08:00
    @css3 出 Permission denied 的时候,docker exec 进去看看你的 /etc/ssh/sshd_config,还有 sshd 的日志。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5545 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 07:08 · PVG 15:08 · LAX 23:08 · JFK 02:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.