Open In App

Manually Add a User Without Tools Like useradd and adduser in Linux

Last Updated : 29 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Adding a user manually in Linux without using tools like useradd or adduser involves modifying system files directly. This method is not recommended for regular use, as it requires careful editing of system files and can lead to errors if not done correctly. However, in some situations, such as when these tools are not available or not working, it can be useful to know how to add a user manually. In this article, we will explain how to manually add a user in Linux

Manually Add a User Without Tools Like useradd and adduser in Linux

This article provides a step by step guide to add user manually, without using “useradd” or “adduser”.

  • useradd: The useradd command in Linux is a tool used to add or create new user on the system. It is mainly used to create user, configuring the login shell of the user.
  • adduser: It is also a user management tool but with a prominent management utility. It is often found in Debian-based distribution such as Ubuntu, Kali Linux, and its derivatives.

It is used to add user simply and it also provides more interactive features such as it adds user with a communal nature such as notifying user with questions and suggestions to assist and configure new user accounts, it also add default configuration and used with default values using various attributes.

Limitations of useradd and adduser tools:

  1. Permissions and Security: Both tools useradd and adduser do not sett up permissions for the user’s home directory or any other resources.
  2. Additional Configuration: For advanced user management tasks, such as setting up user groups, secondary groups, or setting up custom home directory, user might need to use additional commands or do the manual configuration after using tools like adduser or useradd.
  3. Lack of Validation: Both tools do not necessarily validate all parameters, so incorrect usage might lead to unexpected results or errors.

File System changes after creation of new user.

  • The /etc/passwd file is updated with new entry of user.
  • The /etc/shadow file is update with entry of our new user, containing encrypted password information.
  • The new home directory is created in /home directory and the contents of /skel directory is copied in the home directory of new user, which provides default configuration and file directories for the user.
  • The change of permission and ownership of user’s home directory is made to ensure the new user has significant access.

Steps to add user manually in Linux based Operating System

Step 1: Creating User

To create a user manually in linux based OS in this scenario “Ubuntu”, we will edit or add a line in passwd file located in etc directory.

/etc/passwd, the passwd file consist of user information includes seven columns separated by colons.

Syntax:

Username:password:user-id:group-id:user-info:home-directory:login-shell

  • Username: It is the username of the user, it should be between 1 to 32 characters long. Only (‘_’, ‘-’, ‘.’ ) special characters are allowed and cannot contain any spaces, It also should start with a letter, and they are also case-sensitive.
  • Password: It is stored in hashed form, where ‘x’ is the hash stored in shadow file i.e. located in “etc/shadow”.
  • User-id: It is a unique numeric value assigned to uniquely identify the used, it should not be repeated or be same as other user.
  • Group-id: It is also unique numeric value representing group of the user if you want to create the user in the same group you can assign the value of the old group.
  • User-info: In this field the extra info related to user is present separated by comma.
  • Home-directory: It is the absolute path of the home directory of user.
  • Login-shell: It is the path of shell.

etc_passwd

vim_passwd

Step2: Creating Group

As we created group-id for our user in ‘/etc/passwd’ its time to add a group which coordinates with our group-id.

To create a group we will edit the group file which is located in /etc directory i.e. “/etc/group”.

It is similar to the passwd file but contains four columns separated by colons.

Syntax:

Group-name:password:group-id:
  • Group Name: It must be between 1 to 32 characters long.
  • Password: It is stored in hashed form, where ‘x’ is the hash stored in shadow file i.e. located in “etc/shadow”.
  • group-id: Same numeric unique group-id.

The fourth column is left empty, it contains list of usernames separated by commas.
etc_group

demo

Step3: Home Directory

To create a home directory we will use copy command “cp” with -r or recursive attribute and our skeleton directory i.e. “/etc/skel”.

Syntax:

cp --recursive /etc/skel /home/username

roothdir

Replace username with the actual username to create a home directory.

Step4: Changing ownership

The default permission of newly created user is set to root i.e. the “home” of our user belongs to root, to change the permission and the ownership of our user, we will usechmod andchown“.

chown [options] Owner:Group file
  • chown: The chown is a command line tool stands for change owner, it is used to change the owner and group of files and directories.
  • options: In our case we will use “-r” recursive flag with chown to change the ownership of the “home” of our new user.
  • Owner: In place of owner we will assign new user’s username or its unique numeric ID.
  • Group: In place of group we will assign group of our new user or its unique numeric ID.
  • File: In place of file we will assign the path of our “home” as we have to change the permission of home of our user.

demo-hdir

Step5: Changing permission

To change the permission of our user’s home directory we will use chmod with recursive option and mode.

chmod option mode file
  • chmod: The chmod is a command line tool stands for change mode, it is used to change the permission of files and directories. It allows user to set permission who can read, write and execute the file or directory in the system.
  • option: In our case we will use “-r” recursive flag with chown to change the mode of the “home” of our new user.
  • mode: It specifies the permission to be changed, and is represented by symbolic or octal representation.
  • file: It is simply the path of the file or directory whose permission we have to change in our case it is “/home/username“.

perm_demo

Step6: Creating Password

To create password for our newly created user we will use a command line utility passwd“.

Syntax:

passwd username

replace the username with actual username.

passwd

Step7: whoami

To confirm the successful creation of our new user we will login to our new user and confirm the creation of user using whoamicommand.

$ su demouser
Password:
$ whoami
demouser

su-demouser

whoami

Permissions and ownerships

We can also manage the permission and ownership of our user’s home directory for example if we want give read, write and execute permission to user and no permission to group and others, we will assign mode 700 in step 5. We can change and grant permission as per our requirements for user, group and others. We just have to keep in mind that each digit represents the combination of read (4), write (2), and execute (1) permissions and granting permission to user, group and other respectively.

We can also change the ownership of the user, for example we can assign different group to our user’s home directory in step 4

Example:

chown  --recursive demouser:group1 /home/demouser


Security consideration

When adding user manually we should consider the following secure steps to protect against potential vulnerabilities:

  1. Creating a secure password is a first and most common step to make our system more secure.
  2. Assigning appropriate privileges to the new user account is a good step as it limits the use to access the whole system and allows them to perform their intended tasks.
  3. Assuring that the user have the permission of read, write and execute for their own home directory and the access of other’s home directory is denied.
  4. Monitoring user’s activity on the system and maintaining detailed logs of user actions is also a good step towards security as it helps to detect suspicious behavior or unauthorized access attempts.

Manually Add a User Without Tools Like useradd and adduser in Linux – FAQs

What are the essential steps to manually add a user in Linux?

Manually adding a user generally involves creating a new entry in “/etc/passwd “and “/etc/shadow ” file for the user, setting up a home directory, configuring permissions, and optionally adding the user to relevant groups.

What permissions should I set for the user’s home directory?

The user’s home directory generally have mode 700 i.e. only user have the permission to read, write and execute and groups and other’s have no permissions.

Can I simply edit /etc/passwd and /etc/shadow to add a user?

Yes, technically you can edit the files but you must keep the syntax of the file in mind or there will be the risk of errors, else you can also use tools like adduser or useradd.

How to assign a password for new user?

You can simply set password for new user using a command line tool “passwd” .

Can I use shell scripting to automate the manual user creation process?

Yes, shell scripting can be used to automate the manual user creation process. However, it’s crucial to thoroughly test scripts to ensure they function as intended and handle errors gracefully.

Conclusion

In this article we have covered all the necessary steps to manually add a user in Linux. Adding the user manually is complex process but crucial process to create the user, there are several essential steps such as creating a new entry in /etc/passwd file to create and store the information of user, editing /etc/group file to create a group for user. Giving proper permission to user’s home directory and setting up password for more secure environment. But still using tools such as “adduser” or “useradd” for new user creating is recomended as they consumes less time and the chances of error is reduced



Previous Article
Next Article

Similar Reads

How to add User in Linux | useradd Command
useradd is a command in Linux that is used to add user accounts to your system. It is just a symbolic link to adduser command in Linux and the difference between both of them is that useradd is a native binary compiled with the system whereas adduser is a Perl script that uses useradd binary in the background. It makes changes to the following file
4 min read
adduser command in Linux with Examples
adduser command in Linux is used to add a new user to your current Linux machine. This command allows you to modify the configurations of the user which is to be created. It is similar to the useradd command in Linux. The adduser command is much interactive as compared to useradd command. Installing adduser command To install adduser tool use the f
2 min read
Mimic the Linux adduser command in C
Programming for fun can manifest itself in the works of leisurely coding practice as well. Regardless of being academically inadequate, the task certainly does contribute to the programmer's understanding of the resourcefulness of the language. Here let's look at a distinct programming activity that also translates into a low-level insight and flue
9 min read
Netnoob - Network tools, information gathering tools and scanning tools
Netnoob is an automated tool that is developed for Network Recon, Scanning, and Network Auditing. Netnoob tool has the features to Get information about your computer and network, Get information about another computer or a network, Network Settings, and Shared Drives. This tool allows us to change the IP address and MAC Address of our system and a
2 min read
How to make an HTTP GET request manually with netcat?
Netcat,also known as "nc", is a powerful Unix-networking utility that enables users to interact with network services through a command-line interface (CLI). It uses both TCP and UDP network protocols for communication and is designed to be a reliable back-end tool to instantly provide network connectivity to other applications and users. Although
6 min read
User Space Debugging Tools in Linux
In this article, we will discuss debugging tools in Linux. Debugging Tools are those programs that allow us to monitor, control, and correct other program's error while they execute. Some of the debugging tools are as follows:- 'print Statement'Querying (/proc, /sys etc)Tracing (strace/ltrace)Valgrind (memwatch)GDB1. 'print' Statement The 'print' s
3 min read
How to Add User to a Group in Linux
A group in Linux is a way to put users with similar access and permissions in a collection. By using groups, an administrator can define access control and permissions for all the users belonging to that group. Without groups, the administrator would have to define roles for individual users however, with groups those roles can be given to a group
7 min read
How to Add New Disk in Linux CentOS 7 Without Rebooting
Let's Say we hosted the DataBase on our Server Initially with 500GB given space and as we know Database should run 24/7 because the user's using it. One day it consumes space about 400GB only 100GB left Now we want to Increase the Space at the runtime only and In the case of static partitioning we need to restart the server but If we restart the se
3 min read
How to Fix Minimal BASH Like Line Editing is Supported GRUB Error In Linux?
GNU GRUB (Stands for GNU GRand Unified Bootloader) is a boot loader package. It is a part of the GNU project. It is the reference implementation of the Free Software Foundation's Multiboot Specification, that provides a user the choice to boot one of multiple operating systems installed on a computer. It also provides the facility to choose a speci
2 min read
Anonymity and Privacy For Linux User
Today, more than 3 billion of the world's population is connected to the virtual world known as the internet in some way or another. And the size of the hard-wares and data centers is on the increase every year due to insufficient users' information holding capacity. The lack of awareness and knowledge behind the proper functioning of the internet
6 min read
Article Tags :