我的 Dockerfile
FROM ubuntu:latest
RUN apt update
RUN apt install -y openssh-server sudo
RUN useradd -ms /bin/bash -g root -G sudo -u 1000 remote_user
USER remote_user
WORKDIR /home/remote_user
RUN mkdir /home/remote_user/.ssh && chmod 700 /home/remote_user/.ssh
COPY remotecentos.pub /home/remote_user/.ssh/authorized_keys
RUN stat /etc/passwd
RUN echo 'remote_user:*****2599*****' | chpasswd -c SHA256
RUN service ssh start
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]
我有错误
Step 9/13 : RUN stat /etc/passwd
---> Running in 7147677000bd
File: /etc/passwd
Size: 1325 Blocks: 8 IO Block: 4096 regular file
Device: 37h/55d Inode: 22961332 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2022-10-06 12:45:10.000000000 +0000
Modify: 2022-10-06 12:45:10.000000000 +0000
Change: 2022-10-06 12:45:11.197943157 +0000
Birth: 2022-10-06 12:45:11.197943157 +0000
Removing intermediate container 7147677000bd
---> 7b37835f7f2c
Step 10/13 : RUN echo 'remote_user:******' | chpasswd -c SHA256
---> Running in faae63d7fd92
chpasswd: Permission denied.
chpasswd: cannot lock /etc/passwd; try again later.
如何修复容器内的权限?
我应该如何更改密码行?
remote_user
您的 Dockerfile在调用之前将当前用户更改为chpasswd
. 要使用chpasswd
,您需要是 root。您可能希望将该RUN
行(以及任何其他需要超级用户权限的命令)移到该行之前USER
。我也期待ssh
服务的启动会因为类似的原因而失败。