Ubuntu Server

List All User

For students and new users this can be confusing if they don’t know how to read the content of the file… However, each line in the file is  a single account identity… there are seven fields delimited by colons that contain the following:
  • User name
  • Encrypted password (x means that the password is stored in the /etc/shadow file)
  • User ID number (UID)
  • User’s group ID number (GID)
  • Full name of the user (GECOS)
  • User home directory
  • Login shell (defaults to /bin/bash)
Now, if you just want to list the account names and not all the other details, simply run the commands below:
awk -F: '{ print $1}' /etc/passwd
That should list only the account names on the system beginning with the root account..
root
daemon
bin
sys
sync
games
man
......
That’s option number 1

Option #2: Get User List via Getent Tool

Another option to get all user account on the system is to use the getend tool… This tool does similar function as the commands above.. It lists the content of the /etc/passwd file using the database info stored in the /etc/nsswitch.conf file..
To get the lists of users using the getent, run the commands below:
getent passwd
It should list the same content as above:
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
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
........

Reference
https://websiteforstudents.com/how-to-list-all-user-accounts-on-ubuntu-16-04-18-04/

Add User

Steps to Create a New Sudo User

  1. Log in to your server as the root user.
    • ssh root@server_ip_address
  2. Use the adduser command to add a new user to your system.
    Be sure to replace username with the user that you want to create.
    • adduser username
    • Set and confirm the new user’s password at the prompt. A strong password is highly recommended!
      Set password prompts:
      Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
    • Follow the prompts to set the new user’s information. It is fine to accept the defaults to leave all of this information blank.
      User information prompts:
      Changing the user information for username Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]
  3. Use the usermod command to add the user to the sudo group.
    • usermod -aG sudo username
    By default, on Ubuntu, members of the sudo group have sudo privileges.
  4. Test sudo access on new user account
    • Use the su command to switch to the new user account.
      • su - username
    • As the new user, verify that you can use sudo by prepending “sudo” to the command that you want to run with superuser privileges.
      • sudo command_to_run
    • For example, you can list the contents of the /root directory, which is normally only accessible to the root user.
      • sudo ls -la /root
    • The first time you use sudo in a session, you will be prompted for the password of the user account. Enter the password to proceed.
      Output:
      [sudo] password for username:
      If your user is in the proper group and you entered the password correctly, the command that you issued with sudo should run with root privileges.
Reference


Changing Password

How to change a user password in Ubuntu

  1. Open the terminal application by pressing Ctrl+Alt+T
  2. To change a password for user named tom in Ubuntu, type:
    sudo passwd tom
  3. To change a password for root user on Ubuntu Linux, run:
    sudo passwd root
  4. And to change your own password for Ubuntu, execute:
    passwd

How to change a root (superuser) password in Ubuntu

Firstly, open a terminal window. If you want to change the password for remote Ubuntu server, log in using the ssh command:
ssh user@ubuntu-server-ip
ssh vivek@ubuntu-webserver-1

Type ‘sudo -i’ at the command prompt, and Enter key:
sudo -i
Type the current user password and press Enter key. Finally type NA command and press Enter to change password for root user:
passwd

How to change a root user password in Ubuntu Linux
Change password for root user on Ubuntu

Reference

Define Expiry Date for User

Once you have set password expiry and aging information, this information is used by the system to determine when a user must change his/her password. Normally, companies or organizations have certain security polices that demand users to change passwords regularly: this can be a simple way to enforce such policies as we explained below.To view a user account aging information, use the -l flag as shwon.# chage -l raviView User Password Aging Information# chage -d 2018-02-11 ravi# chage -E 2018-02-16 ravi# chage -W 10 ravi# chage -I 2 ravi# man chageView User Password Aging InformationTo set the date or number of days (since January 1, 1970) when the password was last changed, use the -d flag as follows.Next, you can also set the date or number of days (since January 1, 1970) on which the user’s account will no longer be accessible by using the -E switch as shown in the following command.In this case, once a user’s account is locked, he/she is required to contact the system administrator before being able to use the system again.Then, the -W option allows you to set the number of days of warning before a password change is required. Considering the command below, the user ravi will be warned 10 days prior to his password expiring.In addition, you can set the number of days of inactivity after a password has expired before the account is locked. This example means that after user ravi’s password expires, his account will be inactive for 2 days before it is locked.When the account becomes inactive, he must contact the system administrator before being able to use the system again.For more information, refer to the chage man page.Note that you can also change a user’s password expiration and aging information using the usermod command, which is actually intended for modifying a user account.
Reference
Operating System: Ubuntu 14-16
Assigning a user root access is to grant a user the highest power.  My user, Tom, can then make changes to the system as a whole, so it’s critical to allow this access only to users who need it. Afterward, Tom will be able to use sudo before commands that are usually designed to be used by the root user.
usermod -aG sudo tom

Step 3: Verify New User
As root, you can switch to your new user with the su – command and then test to see if your new user has root privileges.
su - tom
If the user has properly been granted root access the command below will show tom in the list.
grep '^sudo' /etc/group
Output:
sudo:x:27:tom

For Ubuntu 18 + 
visudo
The command below leads us to the /etc/sudoers.tmp file where we can view the following code:# User privilege specification
root    ALL=(ALL:ALL) ALL
After the root user line, you’ll add in your new user with the same format for us to grant admin privledges.
tom ALL=(ALL:ALL)ALL
Once you’ve added the permission, save and exit the file by using :wq and enter.

Step 3: Verify User Has Privledges

If you’ve followed the instructions correctly then this user will be able to run commands like, update, using the sudo:
su - tom
sudo apt-get update
Want to do admin tasks through a control panel? Check out our servers that come with cPanel servers.  We offer free migrations and 24/7 support making it effortless to switch to Liquid Web!