Open In App

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

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”.



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.

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

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:

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

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

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

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

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.

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

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


Article Tags :