HOW TO CREATE USERS AND GROUPS IN CENTOS7

HOW TO CREATE USERS AND GROUPS IN CENTOS7?
原文地址:https://manage.accuwebhosting.com/knowledgebase/2959/How-to-create-users-and-groups-in-CentOS7.html

Once the Linux system is configured, adding and removing users is one of the most basic tasks that you should know how to do. When you create a new server, you are only given the root account by default. While this gives you a lot of power and flexibility, it is also dangerous to regularly use an account with so much power; for example, a root user is more vulnerable to security exploits, since any commands run under that account can affect the server's entire filesystem.

It is almost always a better idea to add an additional, unprivileged user to do common tasks. You should also create additional accounts for any other users that need access to your server. Each user should have an additional account so that their activities can be monitored and managed. You can still acquire administrative privileges, when needed, through a mechanism called 'sudo'. We will cover steps for how to create user accounts, assign 'sudo' privileges, and create a group on a CentOS 7 server.

Adding a new user

Log in to your server as the root user.

ssh root@server_ip_address

Use the adduser command to add a new user to your system.

Note: Be sure to replace username with the user that you want to create.

adduser username

Use the passwd command to update the new user's password.

passwd username

Note: Set and confirm the new user's password at the prompt. A strong password is highly recommended!

Creating a usergroup

In order to a create group, you need to use groupadd command:

sudo groupadd NAME-OF-THE-NEW-GROUP

Adding a user to Group

Use the usermod command to add the user to the wheel group.

Note: By default, on CentOS, members of the wheel group have sudo privileges. Be sure to change the username with the actual user which you want to add to the wheel group

usermod -a -G wheel username

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. For example, you can list the contents of the /root directory, which is normally only accessible to the root user.

sudo ls -la /root

Note: The first time you use sudo in a session, you will be prompted for the password of the user account. Enter the password to proceed.

To add a user to multiple groups use below command.

usermod -a -G group1,group2,group3 exampleusername

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,136评论 0 10
  • 要不成就,要不毁灭
    php小生阅读 39评论 0 0
  • 那年你十九岁,我九岁,在一所乡村小学里,我们相遇;如今你三十五岁,我二十五岁,我们依旧保持联系,十六年的岁月,说长...
    凄风苦雨阅读 4,910评论 0 2
  • 现在二胎政策一放开,身边很多人都在跟上政策,有的甚至都是高龄了,还要选择去生。那么,像我这种有个2岁儿女的宝妈,家...
    678my阅读 4,208评论 1 2
  • 在一个没有天才和诗人的时代我只做一句恪守的格言 人生就是走出死亡的过程可是有谁能活着走出来 我们每一个人都以死亡的...
    杨乌那希阅读 2,312评论 0 0