パスワード変更が失敗したのはなぜですか? chpasswd:権限が拒否されました

パスワード変更が失敗したのはなぜですか? chpasswd:権限が拒否されました

私の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.

コンテナ内の権限を変更する方法は?

パスワードラインをどのように変更する必要がありますか?

ベストアンサー1

Dockerfileは、呼び出す前に現在のユーザーをremote_userユーザーに変更しますchpasswd。を使用するにはchpasswdroot権限が必要です。RUNこの行(およびスーパーユーザー権限を必要とする他のコマンド)をUSERこの行の前に移動したい場合があります。また、ssh同様の理由でサービスの開始が失敗することも予想されます。

おすすめ記事