{"id":3287,"date":"2025-02-19T20:41:36","date_gmt":"2025-02-19T20:41:36","guid":{"rendered":"https:\/\/foghosting.com\/how-to-add-users-in-linux-fog-hosting\/"},"modified":"2025-02-19T20:41:36","modified_gmt":"2025-02-19T20:41:36","slug":"how-to-add-users-in-linux-fog-hosting","status":"publish","type":"post","link":"https:\/\/foghosting.com\/blog\/how-to-add-users-in-linux-fog-hosting\/","title":{"rendered":"How to Add Users in Linux? &#8211; Fog Hosting"},"content":{"rendered":"<div>\n<h2><span id=\"Introduction\">Introduction\u00a0<\/span><\/h2>\n<p>One must first become a Linux user to utilize the Linux-based operating system. Each member of the Linux club is assigned a unique user identity, and these users can be grouped. By adding users to groups, they can access specific resources and permissions.<\/p>\n<p>It is important to note that Linux is a multiuser environment, and managing user accounts is a crucial responsibility for system administrators. They are tasked with adding, deleting, and managing users and groups on the system using the \u2018useradd\u2019 command, which offers various options for automating identity and access management.\u00a0<\/p>\n<p>This article explores the add user command and the different methods <strong>to add users in Linux<\/strong>.<\/p>\n<h2><span id=\"Add_user_Command_Syntax\">Add user Command Syntax\u00a0<\/span><\/h2>\n<figure><\/figure>\n<p>It is very easy to <strong>add users in Linux<\/strong> using the \u201cadduser\u201d command syntax. We will understand individual elements of the add user syntax to get detailed knowledge about the process.<\/p>\n<pre><code>adduser [options] username<\/code><\/pre>\n<p>The syntax consists of various elements, and each element has its significance. Let\u2019s understand them one by one.<\/p>\n<ul>\n<li>adduser: This command is the most vital element to add a new user to the Linux system.<\/li>\n<\/ul>\n<ul>\n<li>[options]: The \u2018adduser\u2019 command offers optional command-line options that can alter its behavior. These options allow you to configure additional settings for the user you are adding. Some common options include:<\/li>\n<\/ul>\n<ul>\n<li>-c: This option is used to specify the user\u2019s full name.<\/li>\n<li>-g: Every new user needs a specific primary group which is set by this option.<\/li>\n<li>-s: You need a shell or command-line interface to interact with the computer. This option helps in setting the shell for the new user.\u00a0<\/li>\n<li>-d: Every user has their home directory, which stores their files, settings, etc. This option helps to set up the home directory for the user. Although, you need to specify the detailed path of the home directory.<\/li>\n<li>-m: Similar to the \u201c-d\u201d option, \u201c-m\u201d also creates a home directory for the new user. The only difference is that it does not require extensive details about the path of the home directory.<\/li>\n<li>-e: Inactive accounts pose security risks to organizations which is why user accounts have an expiration date. The user account\u2019s expiration date is set using this option.<\/li>\n<\/ul>\n<ul>\n<li>Username: This placeholder is used to add a user; you must provide the desired username you wish to create. Simply replace \u201cusername\u201d with the preferred name.<\/li>\n<\/ul>\n<h2><span id=\"Creating_New_Users_in_Linux\">Creating New Users in Linux\u00a0<\/span><\/h2>\n<figure><\/figure>\n<h3><span id=\"Adding_a_User_in_Linux_and_Creating_a_Home_Directory\"><strong>Adding a User in Linux and Creating a Home Directory\u00a0<\/strong><\/span><\/h3>\n<p>We will use the \u2018-M\u2019 option to create a home directory for the new\u00a0<\/p>\n<p>user. Look at the command syntax below.<\/p>\n<pre><code>sudo useradd -M <username><\/code><\/pre>\n<figure><\/figure>\n<h3><span id=\"Adding_a_User_with_a_Specific_Home_Directory\"><strong>Adding a User with a Specific Home Directory<\/strong><\/span><\/h3>\n<p>If the home directory already exists, then you need to use the\u00a0<\/p>\n<p>option \u2018-d\u2019. On the other hand, if the home directory is not present,\u00a0<\/p>\n<p>then you will need to use the option \u2018-m\u2019 too. The command syntax\u00a0<\/p>\n<p>will be as follows.<\/p>\n<pre><code>sudo useradd -m -d \/desired\/home\/directory username<\/code><\/pre>\n<figure><\/figure>\n<h3><span id=\"Adding_a_User_without_Home_Directory\"><strong>Adding a User without Home Directory\u00a0<\/strong><\/span><\/h3>\n<p>When a user already has a home directory, the option \u2018-M\u2019 instructs\u00a0<\/p>\n<p>to avoid the creation of a home directory. This option can be\u00a0<\/p>\n<p>included in the following way.<\/p>\n<pre><code>sudo useradd -M username<\/code><\/pre>\n<figure><\/figure>\n<h3><span id=\"Adding_a_User_with_a_Specific_User_ID\"><strong>Adding a User with a Specific User ID\u00a0<\/strong><\/span><\/h3>\n<p>Each user has a unique ID which helps in identifying the permissions\u00a0<\/p>\n<p>and settings of the current user. The tag \u2018-u\u2019 is suitable for adding a\u00a0<\/p>\n<p>user with a specific UID. Follow the below command syntax.<\/p>\n<pre><code>sudo useradd -u UID username<\/code><\/pre>\n<figure><\/figure>\n<h3><span id=\"Adding_a_User_with_a_Specific_Group_ID\"><strong>Adding a User with a Specific Group ID\u00a0<\/strong><\/span><\/h3>\n<p>To add a user to a particular group, utilize the -g tag while creating\u00a0<\/p>\n<p>their profile.<\/p>\n<pre><code>sudo useradd -g <group name or GID> <username><\/code><\/pre>\n<figure><\/figure>\n<h3><span id=\"Adding_a_User_to_Multiple_Groups\"><strong>Adding a User to Multiple Groups\u00a0<\/strong><\/span><\/h3>\n<p>To effortlessly add a user to multiple groups, simply utilize the -G\u00a0<\/p>\n<p>option and input a list of group names or GIDs separated by\u00a0<\/p>\n<p>commas, followed by the username. Allow us to provide you with\u00a0<\/p>\n<p>an example:<\/p>\n<pre><code>sudo useradd -G <group1,group2,group3> <username><\/code><\/pre>\n<figure><\/figure>\n<h3><span id=\"Adding_a_User_with_a_Specific_Login_Shell\"><strong>Adding a User with a Specific Login Shell\u00a0<\/strong><\/span><\/h3>\n<p>Upon creating a new user, a default login shell is automatically\u00a0<\/p>\n<p>assigned, commonly the Bourne shell or Bourne Again Shell.\u00a0<\/p>\n<p>However, if a different shell is desired for the user, confidently use\u00a0<\/p>\n<p>the -s tag and provide the path to the desired shell.<\/p>\n<pre><code>sudo useradd -s <shell path> <username><\/code><\/pre>\n<figure><\/figure>\n<h3><\/h3>\n<p>To add a user with a specific comment, execute the following\u00a0<\/p>\n<p>command.<\/p>\n<pre><code>sudo useradd -c <comment> <username><\/code><\/pre>\n<figure><\/figure>\n<h3><span id=\"Adding_a_User_with_Account_Expiry_Date\"><strong>Adding a User with Account Expiry Date\u00a0<\/strong><\/span><\/h3>\n<p>Add a user with an account expiry date to automatically delete the\u00a0<\/p>\n<p>account after the provided date.<\/p>\n<pre><code>sudo useradd -e <YY-MM-D> <username><\/code><\/pre>\n<figure><\/figure>\n<h3><span id=\"Adding_a_User_with_a_Deactivation_Period\"><strong>Adding a User with a Deactivation Period\u00a0<\/strong><\/span><\/h3>\n<p>When you create a password for a user, you can choose how long\u00a0<\/p>\n<p>the password will be valid. After that time, the account will be\u00a0<\/p>\n<p>deactivated. This gives the user a chance to change the password\u00a0<\/p>\n<p>and reactivate the account.<\/p>\n<pre><code>sudo useradd -f <days> <username><\/code><\/pre>\n<figure><\/figure>\n<h3><span id=\"Adding_a_System_User\"><strong>Adding a System User\u00a0<\/strong><\/span><\/h3>\n<p>It is common for various programs and systems to generate separate\u00a0<\/p>\n<p>user accounts for their specific functions. Such accounts are distinct<\/p>\n<p>from regular user accounts and are crucial for programs like MySQL\u00a0<\/p>\n<p>or Tomcat to operate efficiently on the system. Typically, daemons\u00a0<\/p>\n<p>are responsible for creating these types of accounts during\u00a0<\/p>\n<p>installation.\u00a0<\/p>\n<pre><code>sudo useradd -r <username><\/code><\/pre>\n<figure><\/figure>\n<h3><span id=\"Adding_Multiple_Users\"><strong>Adding Multiple Users\u00a0<\/strong><\/span><\/h3>\n<p>To efficiently add multiple users, the recommended approach is to use a Bash for loop either in a script or directly in the terminal. This will enable you to loop through a list of usernames seamlessly without the need to use the useradd and adduser commands simultaneously.<\/p>\n<pre><code>nano user_list.txt<\/code><\/pre>\n<figure><\/figure>\n<figure><\/figure>\n<p>Also Read: Ping Command Examples for Linux Users<\/p>\n<h2><span id=\"Conclusion\">Conclusion<\/span><\/h2>\n<p>In Linux, adding users is a critical task for system administrators. Each user has a unique identity, and they can be grouped for easier management of permissions and access to resources.<\/p>\n<p>To create a new user in Linux, you can utilize the useradd command along with various options to customize their settings. Moreover, you can use sudo useradd -r <username> to create a system user account. This account type is specifically used for running particular programs or services on the system.<\/p>\n<p>If you need to add multiple users in Linux, you can use a Bash for loop to loop through a list of usernames and add them all at once. Managing users and groups is a vital aspect of maintaining a secure and organized Linux environment. By appropriately adding users and configuring their settings, system administrators can effectively control access to resources and ensure the smooth operation of the system.<\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction\u00a0 One must first become a Linux user to utilize the Linux-based operating system. Each member of the Linux club is assigned a unique user identity, and these users can be grouped. By adding users to groups, they can access specific resources and permissions. It is important to note that Linux is a multiuser environment<\/p>\n","protected":false},"author":3,"featured_media":3076,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[17],"tags":[],"class_list":["post-3287","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dedicated-servers"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/posts\/3287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/comments?post=3287"}],"version-history":[{"count":0,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/posts\/3287\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/media\/3076"}],"wp:attachment":[{"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/media?parent=3287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/categories?post=3287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/tags?post=3287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}