Users on linux server

How to List Users on Ubuntu Linux VPS

As expected, managing multiple server users at a time is a daunting task and system administrators have had to find a way to effectively control user interaction on the system.

Reasons to View System Users in Ubuntu

It’s a well-known fact that the Linux server is the most preferred server among tech-enthusiasts for quite a number of amazing reasons. First, the Linux server is very powerful and can support the performance of as many activities you would like to carry on. It is open-source, safe and secure, has an amazing community, is always improving on features and is highly cost-effective.

As a result of the many benefits the Linux server offers especially for tech-personnel, it has become the favorite server for many groups and organizations and is used by many for team-based projects and collaborative works especially because it allows multiple logins. As such, the Linux server has multiple users at a time.

As expected, managing multiple server users at a time is a daunting task and system administrators have had to find a way to effectively control user’s interaction on the system. Ubuntu VPS features have been effective in achieving this and have helped administrators carry out functions like modifying systems, granting access to Ubuntu list users to view certain data, etc.

For security reasons, you would need to see permissions and verify the activities of other Ubuntu list users and as such, it’s important for you to know how to list users on your Ubuntu VPS before configuring the settings.

How to List Users on Ubuntu

To list users on Ubuntu VPS is to know the numbers of Ubuntu list users as well as verify their activities on the system.

You can view Ubuntu list users in 3 ways:

1.Viewing Ubuntu list Users using the/etc/passwd File. You would need less or cat to access this file which has the information of local Ubuntu list users stored in it. This is the syntax:

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
johndoe:x:1000:1000:John Doe. /home/helder:/bin/bash
davmail:x:127:65534::/var/lib/davmail:/usr/sbin/nologin
statd:x:128:65534::/var/lib/nfs:/usr/sbin/nologin

A careful observation would show that there are 7 fields in each line and each of them contains basic information like the username, user ID, encrypted password, group ID number, full name, user home directory and login shell of the Ubuntu list users.

2. Viewing Ubuntu list Users using the getent command: Viewing Ubuntu list users with the getent command will propose similar results as the etc/passwrd. It can, however, be used to query a list of all users through displaying entries from databases configured in /etc/nsswitch.conf file and the passwrd database.

3. Viewing Ubuntu list users using the compgen command: To view the usernames of Ubuntu list users without more, the compgen command would come in handy. To achieve this, you would use the -u function and the result would be like this:

Читайте также:  Linux remote run script

root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
gnats
nobody
systemd-network

gdm

You can also use the compgen command with the -c option when you don’t have sudo access or you are not the admin on a linux system, to list all the commands available to you.

You can use the grep command to check if a user exists on a Linux system using this syntax: getent passwd | grep jane assuming the user’s name is Jane. Jane’s login details will be displayed if she’s a user and if she’s not, there would be no output.

Viewing All Users on Linux

To view all Ubuntu list users on your Ubuntu VPS / Linux server, you would need to access the content of the passwrd file which contains all the information about all registered Ubuntu list users. The file is located in the /etc/passwd.
On your VPS terminal, type less /etc/passwd and expect to see a password like this:

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh

Each line contains information about the username, password, User ID, Group ID, full name, home directory and user shell of the Ubuntu list users in that order.

Viewing Groups on Linux

The Linux server allows the VPS users to create and group Ubuntu list users to make it easier to grant a group of people access especially if they are using the same system. While individual information of Ubuntu list users is stored in /etc/passwd, the information of a group is stored in /etc/group.

To access the information on this file, go to your VPS terminal, and type less /etc/ group

Expect the following output:

The Linux server uses the UPG scheme which allows Ubuntu list users to have their personal private group.

Viewing Logged In Users

The process of viewing logged in Ubuntu list users is an easy one. All you need to do is open your VPS terminal and type this command: w

The result will show you the active Ubuntu list users and also include extra information about the remote host, login time, etc.

Here’s a breakdown of the result:

User – This is the username of the Ubuntu VPS/ server user

TTY- This is the terminal name of the VPS/ server user

From- The remote hostname of the VPS/ server user

[email protected] – Details of the login time of the VPS/ server user

Idle – The idle time of the VPS/ server user

JCPU- This displays information about the length of time the processes attached to the TTY uses.

PCPU- This displays information about the time used by the process in the WHAT field.

WHAT- This displays information about the user’s current process.

The “who” command performs similar functions with the w command. However, it does not display as much detailed output as the w command does. The “who” command displays an output that looks like this:

Источник

How to Add and Delete Users on Ubuntu 20.04

How to Add and Delete Users on Ubuntu 20.04

Adding and removing users on a Linux system is one of the most important system administration tasks to familiarize yourself with. When you create a new system, you are often only given access to the root account by default.

While running as the root user gives you complete control over a system and its users, it is also dangerous and possibly destructive. For common system administration tasks, it’s a better idea to add an unprivileged user and carry out those tasks without root privileges. You can also create additional unprivileged accounts for any other users you may have on your system. Each user on a system should have their own separate account.

Читайте также:  Перехват bluetooth kali linux

For tasks that require administrator privileges, there is a tool installed on Ubuntu systems called sudo . Briefly, sudo allows you to run a command as another user, including users with administrative privileges. In this guide, you’ll learn how to create user accounts, assign sudo privileges, and delete users.

Prerequisites

To complete this tutorial, you will need access to a server running Ubuntu 20.04. Ensure that you have root access to the server and firewall enabled. To set this up, follow our Initial Server Setup Guide for Ubuntu 20.04.

Adding a User

If you are signed in as the root user, you can create a new user at any time by running the following:

If you are signed in as a non-root user who has been given sudo privileges, you can add a new user with the following command:

Either way, you will be required to respond to a series of questions:

  • Assign and confirm a password for the new user.
  • Enter any additional information about the new user. This is optional and can be skipped by pressing ENTER if you don’t wish to utilize these fields.
  • Finally, you’ll be asked to confirm that the information you provided was correct. Press Y to continue.

Your new user is now ready for use and can be logged into with the password that you entered.

If you need your new user to have administrative privileges, continue on to the next section.

Granting a User Sudo Privileges

If your new user should have the ability to execute commands with root (administrative) privileges, you will need to give the new user access to sudo . Let’s examine two approaches to this task: first, adding the user to a pre-defined sudo user group, and second, specifying privileges on a per-user basis in sudo ’s configuration.

Adding the New User to the Sudo Group

By default, sudo on Ubuntu 20.04 systems is configured to extend full privileges to any user in the sudo group.

You can view what groups your new user is in with the groups command:

By default, a new user is only in their own group because adduser creates this in addition to the user profile. A user and its own group share the same name. In order to add the user to a new group, you can use the usermod command:

The -aG option tells usermod to add the user to the listed groups.

Please note that the usermod command itself requires sudo privileges. This means that you can only add users to the sudo group if you’re signed in as the root user or as another user that has already been added as a member of the sudo group. In the latter case, you will have to precede this command with sudo , as in this example:

Specifying Explicit User Privileges in /etc/sudoers

As an alternative to putting your user in the sudo group, you can use the visudo command, which opens a configuration file called /etc/sudoers in the system’s default editor, and explicitly specify privileges on a per-user basis.

Читайте также:  Linux get ip address bash

Using visudo is the only recommended way to make changes to /etc/sudoers because it locks the file against multiple simultaneous edits and performs a validation check on its contents before overwriting the file. This helps to prevent a situation where you misconfigure sudo and cannot fix the problem because you have lost sudo privileges.

If you are currently signed in as root, run the following:

If you are signed in as a non-root user with sudo privileges, run the same command with the sudo prefix:

Traditionally, visudo opened /etc/sudoers in the vi editor, which can be confusing for inexperienced users. By default on new Ubuntu installations, visudo will use the nano text editor, which provides a more convenient and accessible text editing experience. Use the arrow keys to move the cursor, and search for the line that reads like the following:

Below this line, add the following highlighted line. Be sure to change newuser to the name of the user profile that you would like to grant sudo privileges:

root ALL=(ALL:ALL) ALL newuser ALL=(ALL:ALL) ALL 

Add a new line like this for each user that should be given full sudo privileges. When you’re finished, save and close the file by pressing CTRL + X , followed by Y , and then ENTER to confirm.

Testing Your User’s Sudo Privileges

Now your new user is able to execute commands with administrative privileges.

When signed in as the new user, you can execute commands as your regular user by typing commands as normal:

You can execute the same command with administrative privileges by typing sudo ahead of the command:

When doing this, you will be prompted to enter the password of the regular user account you are signed in as.

Deleting a User

In the event that you no longer need a user, it’s best to delete the old account.

You can delete the user itself, without deleting any of their files, by running the following command as root:

If you are signed in as another non-root user with sudo privileges, you would use the following:

If, instead, you want to delete the user’s home directory when the user is deleted, you can issue the following command as root:

If you’re running this as a non-root user with sudo privileges, you would run the same command with the sudo prefix:

If you previously configured sudo privileges for the user you deleted, you may want to remove the relevant line again:

Or use the following command if you are a non-root user with sudo privileges:

root ALL=(ALL:ALL) ALL newuser ALL=(ALL:ALL) ALL # DELETE THIS LINE 

This will prevent a new user created with the same name from being accidentally given sudo privileges.

Conclusion

You should now have a fairly good handle on how to add and remove users from your Ubuntu 20.04 system. Effective user management will allow you to separate users and give them only the access that they are required to do their job.

For more information about how to configure sudo , check out our guide on how to edit the sudoers file.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Источник

Оцените статью
Adblock
detector