Create a new user in Linux and give permissions to the specified directory

  • 2021-07-09 09:45:50
  • OfStack

1 Create a user and specify the root path and password of the user


useradd -d /home/mydir -m username

Users created in this way can log in using ssh, but only read-only rights can browse and download some files, and cannot write and modify them.

It is recommended that users be added to 1 group to gain permissions on the specified path.

2 Set the password

passwd username

3 User Authorization


chown -R username: username /home/ mydir
chmod 755 /home/mydir

4 Join a user to a group

Add 1 user to a user group, and try not to use it directly (unless it really belongs to only 1 group):

usermod -G groupA username

Doing so will take you away from other user groups and just be a member of this user group groupA.

You should add the-a option:

usermod -a -G groupA username

View the group usage command to which the user belongs

groups username

Summarize


Related articles: