Những lệnh linux về User và Group thường dùng

Create a new user and group

# Add user dev
useradd dev

# Add user group
groupadd group_dev

# Set password user dev
passwd dev
# Set password user and group
gpasswd -a user_dev group_dev

# Set owner folder user dev and group dev
chown -R user_dev:group_dev /var/www/folder/
# Set owner user
chown -R user_dev /var/www/folder
# Set owner group
chgrp -R group_dev /var/www/folder

# Set permission
chmod -R g+rw /var/www/folder

# View list user
cat /etc/passwd

# Delete/Remove user
userdel userName
userdel [options] userName
userdel -r userName

# ADD user used direct path
usermod -d /var/www/folder/ user_dev
  • “/var/www/folder/”: folder path owner
  • “group_dev”: Group user name
  • “user_dev”: User name

Create a New Sudo User

  1. Log in to your server as the root user
  2. Use the adduser command to add a new user to your system.
  3. Use the usermod command to add the user to the wheel group.usermod -aG wheel username
  4. By default, on CentOS, members of the wheel group have sudo privileges.
  5. Test sudo access on new user account
    • Use the su command to switch to the new user account.su – username
    • As the new user, verify that you can use sudo by prepending “sudo” to the command that you want to run with superuser privileges.sudo command_to_run
    • For example, you can list the contents of the /root directory, which is normally only accessible to the root user.sudo ls -la /root

Sliding Sidebar

About Me

About Me

Hello, my name is Dũng (Johnny). Welcome to my blog.

As I’m a developer, I write about topics related to the field of programming, mainly from a technical point of view. On this blog you’ll find posts which encourage discussion, information about development trends, case studies, reviews, tutorials, tips on how to improve your effectiveness, and anything else that might be fascinating to people from the IT industry.
I love PHP, NodeJS, Java,... and Fullstack.