0

My 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"]

I got error

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.

How to fix permissions inside container?

How should I change the passwd line?

1 Answer 1

1

Your Dockerfile changes the current user to remote_user before invoking chpasswd. To use chpasswd, you need to be root. You might want to move that RUN line (and any other command that requires super-user privileges) before the USER line. I'm also expecting that the starting of the ssh service will fail for similar reasons.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .