2 Ways to Create a User With Access to a Drive in Ubuntu

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

Ubuntu is an open-source multiuser Operating System that allows multiple users to use the same computer system simultaneously. To ensure security and data privacy, Ubuntu allows passwordprotected accounts. Besides, it sets different types of permissions to access or modify files. Anyway, in some cases, you may need to create a user that can have access to some particular drive of other users. In this article, I will discuss how to create a user with access to a drive in Ubuntu using both Terminal and GUI.

Key Takeaways

  • Creating a user using both Terminal & GUI.
  • Adding drive access permission to the user.
  • Familiarizing with the sudo, adduser, chown, chmod, mount & some other commands in Linux.

Requirements

  • To create, remove, or modify a user in Ubuntu, you must either be the root user or have root/sudo privileges.
  • When selecting a username, make sure to use only lowercase letters & avoid spaces with some special characters such as asterisks (*), question marks (?), or brackets ([ ]). Well, you can add numbers and some special characters including underscore (_), period (.), or hyphen (-).

Process Flow Chart

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTSProcess Flow chart of creating user with drive access in ubuntu.

Watch 2 Methods to Create a Drive Accessible User in Ubuntu

2 Methods to Create a User with Access to a Drive in Ubuntu

Creating a user with special drive access can be vital in some cases whenever the user needs to access some specific applications or perform certain administrative tasks. Moreover, it is important to learn about sharing specific files while restricting others. Here, I will show you two ways to create a user with drive access.

You can read the Comparative Analysis of Methods section to distinguish between these two methods and best pick one for your need.

Method 1: Using GUI to Create a User with Access to a Drive in Ubuntu

You can easily create a user using GUI in Ubuntu and give it access permission to any drive. GUI is simple in addition to a clear-cut solution when you can’t remember specifically which command to use in the command prompt to execute the task. Now, I will give step-by-step instructions to create a user & grant it drive access via GUI.

Steps to Follow >

➊ At first, go to your Ubuntu settings menu.Ubuntu settings menu to create a user➋ Next, search “Users” from the search option and select the ‘Add or remove users and change your password’ option.Users Application of Ubuntu➌ After that, select Unlock option to perform any action as administrator.Unlock to add a new user in ubuntu.➍ Afterward, authenticate your user account by entering the password for the currently logged-in user.Authenticate by providing current user password.➎ Then, Click the Add User option at the top right corner.Click Add user option to create new user with drive access ubuntu.Select the account type Administrator to give administrative privileges to the new user. Set the username, and password. Then, click on the Add option.Add new user name & set password.➐ Finally, Authenticate your current account by typing the password & your new user will be created.Authenticate to add new user.➑ For the next phase, go to your files & right-click on any drive you want to give the new user access to. Select the “Properties” option from the list.Open drive permissions.➒ After that, go to permissions & click on “groups”.Click on drive groups to give user drive access.➓ Afterward, from the group list, select the new_user group name. This way, the user will have access to this drive.Add new user group as the drive access group. With the successful completion of the outlined steps above, you will be able to create a new user and give any drive access to it. After that, you can switch to the new user using the terminal or GUI, to check if you can access the drive.

Method 2: Using Terminal to Create a User with Access to a Drive in Ubuntu

The fastest way to create a user with access to a drive is by command line interface (CLI) via the terminal. You can easily create a user using the adduser command from the command prompt and then permit to access the drive using the chown command. Go through the below steps to perform the process practically.Process chart to create new user using terminal with drive access ubuntu.

Step 1: Create a User

The distribution provides two different commands to create a new user. First, create a user using the adduser or useradd command. Here, I will create a user using the adduser command.

Command Syntax

sudo adduser USER_NAME

Steps to Follow >

➊ Open your Ubuntu terminal application.

➋ Type the following command in your command prompt to create a user:

sudo adduser new_user
EXPLANATION
  • sudo: permits administrative privileges.
  • adduser: creates a new user.
  • new_user: name of the newly created user.
➌ Tap the ENTER key.

➍ Give the currently logged-in user password.

➎ Then, hit the ENTER button again.Add a new user with the adduser command in ubuntu.

EXPLANATION

After entering the password, the command will add the new user to a new group, with the same name as the username. Moreover, it will create a home directory for storing the new user’s data.

After that, the command copies the contents of the “/etc/skel” directory to the new user’s home directory. The “/etc/skel” directory contains a set of default files and directories which provide a basic set of files and settings for the user.

➏ After that, type & retype the new user password with other information. However, you can skip setting other information by pressing ENTER each time.

➐ Finally, press ‘Y’ to confirm the new user creation.Set new password for the new user.



Step 2: Add User to Group

By default, a new user is only a member of their own group. Now, to give the new user access to the drive, you have to add it to the appropriate group. For example, add the user to the “disk” group, which provides read/write access to block devices, such as hard drives and flash drives.

Command Syntax

sudo usermod [Options] GROUP_NAME USER_NAME

Steps to Follow >

➊ Write the following command in the command prompt to add the new user to the “disk” group:

sudo usermod -aG disk new_user
EXPLANATION
  • usermod: Modifies assigned attributes to the user.
  • -aG: This option of the usermod command adds the user to an additional group.
  • new_user: Username of the newly created user.

➋ Press the ENTER key.Add the newly created user to the disk group. The usermod command is modifying the new_user by adding it to the additional “disk” group.

Step 3: Add Permissions to Modify the Drive

After you have created a new user and added it to the “disk” group, now you have to work on the drive, to which you want the user to have access. Check the mount point of the drive (location of the drive) and then add appropriate permissions to the directory, so that the new user can read, write or execute after accessing.

Command Syntax

sudo chmod +Permissions /path/to/the/drive

Steps to Follow >

➊ Type the following command in the command prompt to set permissions to the drive:

sudo chmod +rwx /media/drive/share
EXPLANATION
  • chmod: changes access permission of files & directories.
  • +rwx: read-write-execute permissions.
  • /media/drive/share: Drive location path.

➋ Hit the ENTER button.

➌ Give the password and ENTER again.Add read, write & execute permission to the group. The chmod command is adding read-write-execute permissions to the drive.

Step 4: Give User Drive Ownership

Next, add the newly created user as an owner of the drive. To do so use the chown command & as an argument give the new username along with the drive location path.

Command Syntax

sudo chown USER_NAME  /path/to/the/drive

Steps to Follow >

➊ Write the following command to add the ownership of the drive to the new user:

sudo chown new_user /media/drive/share
EXPLANATION
  • chown: Changes ownership of files & directories.
  • /media/drive/share: Location path of the drive.

➋ Press the ENTER key.Add the new user as the ownership of the drive. The chown command is adding the new_user as an owner of the drive /media/drive/share.

Comparative Analysis of Methods

In this article, I showed you how to create a user and give it access to a drive both using GUI & terminal. Anyway, check the following table where I have comparatively analyzed the pros & cons of both methods.

Methods

Pros

Cons

Method 1
  • User-friendly & easy to use.
  • Does not require any knowledge of commands.
  • The visual representation can help beginner-level users.
  • Slower due to clicking and navigation.
  • Does not provide the same level of functionality as the CLI.
Method 2
  • Faster for advanced users who can execute commands quickly.
  • Offers scripting options for bulk user creation and management.
  • Requires familiarity with CLI.
  • Increased possibility to make mistakes due to manual typos and syntax errors.

In summary, both methods have their own pros and cons. Now, if you have good CLI knowledge and feel more comfortable using it over GUI, then use method 2. On the other hand, if you are not sure about some commands or facing unknown errors then use method 1.



Complementary Information

Besides, knowing about creating new users with drive accesses, you will find the below information helpful.

Check If the Newly Created User Exists in Ubuntu

After you have completed the new user account creation, verify if it has been created successfully. For that, try to find the new user name from the users’ list by using the following command syntax.

Command Syntax

getent passwd | grep USER_NAME

Now, I will check if my newly created user named “new_user” exist on the system. You can do so by following the given steps.

Steps to Follow >

➊ Open the Ubuntu terminal.

➋ Then, type the following command into the command prompt:

getent passwd | grep new_user
EXPLANATION
  • getent: Looks into the administrative database that is given as its argument.
  • passwd: Contains user information.
  • Pipe (|): Redirects the standard output.
  • grep: Looks for a specific pattern given to it as an argument.
  • new_user: The username of the newly created user to be checked.

➌ Finally, Press the ENTER button.Verify if the newly created user exists on your computer.

EXPLANATION

From the above image, you can see that the newly created user account “new_user” is present on the system. Each command output part represents the following info:

new_user: Name of the user account.

x: Password field in a non-readable format ‘x’. which means that the password is stored in the /etc/shadow file.

1001: The user ID (UID) for this user.

1001: The group ID (GID) for this user.

MOON: Full name of this user.

,,,: Comment field. These three consecutive commas mean that for this user it is empty.

/home/new_user: Home directory of this user.

/bin/sh: Default log-in shell of this user.

Examine If the Newly Created User has Access to the Drive

After that you have created a new user and granted access to a drive, next, let’s verify if the user really has permission to access the drive. For that, at first, switch to the new user using the following command syntax.

Command Syntax

su - USER_NAME

Follow the below steps to complete the process.

Steps to Follow >

➊ Start by opening the terminal

➋ Then, write the below command in the command prompt to log in to the newly created user:

su - new_user

➌ Tab the ENTER button.

➍  Give the new_user password & hit the ENTER key again.

➎  After that, you will be logged in to the new_user. Now, let’s see if you can access & view the drive. For that, change the current working directory to the drive directory by the following command:

cd /media/drive/share
EXPLANATION
  • su: switches between users.
  • cd: change the current working directory.
  • ls: List all the file or directory contents.

➏ Tab ENTER & then, view the list of all files using the ls command.Verify if the new user can access the specified drive.

EXPLANATION
After running the su command, you will switch to the new user. Afterward, change your working directory from new_user’s home to the drive’s directory. If you didn’t have access to the drive then the output would have shown “permission denied”. As you have access permission, you can further view directory contents along with modifying them.

List All Users on Ubuntu

In method 1, while using GUI, you can see all users list from the Users section of applications. Now, what if you want to check all users list with their UID, GID, and home directory location using the terminal, then follow the below command syntax:

Command Syntax

getent passwd {User ID range}

Steps to Follow >

➊ Open the Ubuntu terminal.

➋ Type the following command in the command prompt:

getent passwd {1000..60000}
EXPLANATION
  • getent: retrieves entries from a specified database.
  • passwd: password database.
  • {1000..60000}: User IDs ranging from 1000 to 60000.

➌ Press ENTER key.View all available system users in ubuntu.

EXPLANATION
The output shows all the system’s listed users along with their info. I have three users in my system named munny (UID: 1000) (currently logged-in user), new_user (UID:1001), and hawaimithai (UID:1002). You can see their full name & home directory path too.


Give the New User Access to an External Drive in Ubuntu

Throughout the article, you learned how to give access to an internal drive to a newly created user. Now, what if you want to give the user access to an external drive? Well, the process is almost the same but you need some extra work. Follow the below steps to perform the process.

Steps to Follow >

➊ At first, plug in any external drive such as a USB drive.

➋ Next, open the Ubuntu terminal.

➌ Now, check all your system disks list using to view USB disk info by the following command:

sudo fdisk -l
EXPLANATION
  • fdisk: manipulate disk partition table.
  • -l: used to show the list.
View all system disks list using the fdisk command in ubuntu.From the command output, you will see all your system disks information. If you scroll through the list, tt the bottom of the list, you will find your USB disk info like device name, size, label, identifier, etc.View USB drive info and device name.➍ Next, mount the USB drive with the read-write option using the following command:

sudo mount -o rw /dev/sdc1 /media/munny/USB1

➎ Afterward, check the mounted file list to see if the drive was mounted successfully by the below command:

df -h
EXPLANATION
  • mount: mounts files or external drives to the Linux system filesystem.
  • -o rw: executes read-write mount option.
  • df: displays all disks used & free spaces.
  • -h: shows value in human-readable

Mount the external USB drive using the mount command in ubuntu.When you run the command to mount the drive, it will be mounted if no error message is shown and a new command prompt pops up as the output. Next, check the list of mounted files and you will notice the drive USB1 is listed at the bottom as it was mounted at last.

➎  Finally, add the new user as the owner of the drive by the following command:

sudo chown new_user:new_user /media/munny/USB1

➏ Press the ENTER button.Chnage the drive ownership. After these steps, your new user will have access to the external drive. You can follow these simple steps to give any user any external drive access.

Conclusion

To sum up, while using multiuser LINUX OS, it is very important to learn how to create users and distribute different types of permissions among them. Since this enhances security, control, and accountability between them. In this article, I tried to explain how to create a user with access to drive in Ubuntu and verified it with examples. Besides, I added some complementary info that will be helpful to gather some extra knowledge. Happy learning!

People Also Ask

How do I give permission to a user folder in Ubuntu?
You can set read, write, or execute permission to a folder using the “chmod” command in Ubuntu. You can use the command in either absolute (numeric such as 750, 777) or symbolic mode ( with symbols like +,-,u,g,o,r,w,x) to set permissions to the folder.
How do I create a new user account with admin access in Ubuntu?
From the command line, you can create a regular user using the adduser or useradd commands and then add it to the sudo group to make it an admin user. However, while creating a user through the GUI you can choose the option of Administrator Account Type to create an admin.
How do I create multiple users in Ubuntu?
You cannot create multiple users at the same time from the CLI or GUI. However, as a root user, you can always create additional users in your system using the adduser or useradd commands from your terminal. However, you can write an executable bash script using these commands to automate the creation of multiple users.
How do I set full permissions chmod 777?
If you want to make all the files in the current directory have all permissions types (7-owner, 7-group, & 7-others), then use this command syntax “chmod -R 777 ./”, here option -R makes the process recursive.
How do I create a user in Linux without root privileges?
You can create a user without root privileges, while using GUI, create the user in the standard section. Moreover, when you are using the terminal, in that case, don’t add the user to the sudo group.
Can we create a user in Ubuntu without being a root user?
You must have sudo privileges to create a new user. Say, you are logged in as a non-root user however you have sudo privileges, then you can add a new user by using the sudo command with the adduser command.
SHow do I create a non-login user in Linux?
To create a non-login system user in Linux, use the adduser command with the -system option. Since system users don’t need any password to log in therefore you don’t need to assign a password.
Can I create two users with the same name in Linux?
Yes, it is possible to create two users with the same username by specifying two different UIDs for them. However, remember that it is not recommended to use the same username because it will create confusion and difficulty in permission management.
Can two users have the same UID in Linux?
Yes, two or more users can be assigned to the same user ID (UID). However, it would be best if you were careful while doing that because users with the same UID will share everything.
How to delete a user in Ubuntu?
If you are a root user or have root privileges, you can delete a user from the settings>users or use the userdel command from the Terminal.
Relaed Articles

Rate this post
Monira Akter Munny

Hello!! This is Monira Akter Munny. I'm a Linux content developer executive here, at SOFTEKO company. I have completed my B.Sc. in Engineering from Rajshahi University of Engineering & Technology in the Electrical & Electronics department. I'm more of an online gaming person who also loves to read blogs & write. As an open-minded person ready to learn & adapt to new territory, I'm always excited to explore the Linux world & share it with you! Read Full Bio

Leave a Comment