Docker Community Forums

Share and learn in the Docker community.

Usermod: Permission denied

Hi,
My website, on the docker (run Windows10).

I have a [public] directory and the website’s user put an image into the this directory.
I use the windows terminal >>> Ubuntu
$ ls -l
and Iget this response :

drwxrwxrwx 1 beginnerjdocker beginnerjdocker 4096 Apr 25 11:22 public
I think [beginnerjdocker] user must add into the [www-data] group

I tried two way but it doesn’t work :slight_smile:
adduser beginnerjdocker www-data

adduser: Only root may add a user or group to the system.

usermod -aG www-data beginnerjdocker

usermod: Permission denied.|
usermod: cannot lock /etc/passwd; try again later.

Could you help me : how I can do it ?

thanks

So you have two issues here.

The first is that the new user you created cannot create a new dir. This is because, even though you’re changing users (user → root → user1), you’re still in the home directory of user, which user1 can’t write to. What you need to do is either specify a user directory when you create the user, (useradd -d /home/user1 user1), as @fedorqui mentioned, or, if you’ve already created user1, use the usermod command to add a home directory to user1, like this:

usermod -d /home/user1 user1
If /home/user1 does not exist, you’ll need to, as root, do the following:

mkdir /home/user1
chown -R user1 /home/user1
What this is doing is first creating the directory, and then assigning ownership of it to your newly created user. So now, when you do su - user1, you’ll end up in /home/user1. You should now be able to create directories and files.

Your second issue, “user1 is not in suboers file.”, is a result of how sudo manages which users are allowed to use it. The rules that control this are in /etc/sudoers, which you should edit with visudo. If you wanted to allow user1 to run whatever they want with sudo, you could add a line like this:

user1 ALL=(ALL) ALL
Which says that user user1 may run any command on the system as root. If you now try to run a command with sudo as user1, it will prompt you for user1’s password and then run the command.

Thanks lewish95, :grinning:
Following your explanation, I managed to add my user [beginnerjdocker] to the another group [www-data]

sudo adduser beginnerjdocker www-data

But I can not change the right to my directory, [public]

Nows, it is like this :

drwxrwxrwx 1 beginnerjdocker beginnerjdocker 4096 Apr 25 10:34 public

how can I get it like this :

drwxrwxrwx 1 beginnerjdocker www-data 4096 Apr 25 10:34 public

I tried it two different way like this

sudo chown -R beginnerjdocker:www-data ./public
and all directory :
$ sudo chown -R beginnerjdocker:www-data .
But nothing is changed :unamused: