Basics of Linux – Part 1 (User and Group Management)

Basics of Linux – Part 1 (User and Group Management)

In this tutorial, we’ll be diving into the basics of Linux

(Bonus Learning: We will be learning to use an ubuntu docker container as our environment to play around to learn about the basics of Linux)

What is an Operating System ?

  • In simple language, an operating system is the bridge between the hardware and the software of a Computer System
  • It manages all the communication and interaction between hardwares and softwares

What is Linux and Why Linux ?

  • Smartphones, Cars, Home Appliances, Enterprise Servers, Home Desktops and many more are places where linux is commonly used as the operating system
  • Most of the internet runs on Linux
  • In simple terms, linux is an operating system just like Windows, MacOS
  • One of the most popular and most used platform, Android is based on the Linux operating system
  • What makes linux special is that it is an open source operating system, i.e., it is maintained and developed by the open source community and you can use it for free unlike many other operating systems which require a paid license
  • Open source also means that you can dive into the code base of your OS and understand how it entirely works and how it is put together
Ubuntu

Environment Setup

If you have access to a Desktop / Laptop / Virtual Private Server / RaspberryPi etc., running the Ubuntu Linux Distro, you can feel free to use it. For the purpose of this tutorial, we will be using Ubuntu to learn the basics of Linux. However, feel free to use a Linux distro of your choice but make sure to verify the respective commands as per your Linux distro

If you do not have access to any of the above, we can easily achieve this with docker. Follow along to learn how to set this up

Bonus: Run Ubuntu on Docker

There are major limitations to running ubuntu by this method, but to start with and understand a few basic commands this should be just fine.

  1. Make sure to install docker and docker compose. Refer this previous blog for this: Docker and Docker-Compose on Ubuntu
  2. Run the below command to run ubuntu on docker
docker run -it ubuntu /bin/bash

This command will run docker with two flags:
-i -> Run the container in interactive mode
-t -> Allocate a pseudo-TTY

The ubuntu image is pulled and is launched in interactive mode with a bash session on the container through which we will be interacting with the container

Ubuntu

User management in Ubuntu

There are mainly two types of users that can be created:

  1. Normal User
  2. System User

On running the below commands, the details like password and some information for the user are requested. You can skip through by just pressing enter and at the final prompt where it required for the verification of the information you can enter ‘Y’ to successfully complete the process.

When running these commands on a docker container, sudo is not required. But when running the commands on an actual ubuntu machine, you will need to prefix each command with sudo

# Prefix sudo to all these commands when using on an actual ubuntu machine
# When running on a container sudo will not be required
# To create a Normal User
adduser <username>
# To create a System User
# This command will not work on the docker container
adduser --system <username>
Ubuntu
# List all users 
cut --delimiter=: --fields=1 /etc/passwd
Ubuntu
# To switch to a particular user
su - <username>
Ubuntu
# To change the password of a user, first switch to the required user and run the passwd command
passwd
Ubuntu
# To delete a user
deluser <username>
# In order to remove a user you must be root as shown below (or) run the command with sudo on a user who has root permissions
# To delete a user and also remove the home directory i.e., all the files of a user
deluser --remove-home <username>
Ubuntu

Group Management in Ubuntu

A group is simply just a collection of users. A group is helpful when permissions for a particular resource need to be given to a certain group of users. Users can be added and removed from groups easily allowing to define privileges on a group level that applies to all users of the group

# To create a group on linux, use the below command
addgroup <groupname>
Ubuntu
# List all groups on the machine
cut --delimiter=: --fields=1 /etc/group
Ubuntu
# Add a user to a group
usermod -aG <groupname> <username>
# To view the group of a user first switch to the user
su - <username>
# Show all the groups of which the user if a part of
groups
Ubuntu
# List all users of a particular group
cat /etc/group | cut --delimiter=: --fields=1,4 | grep <groupname>
Ubuntu
# To remove a user from a group 
# You have to be root or a user with root permission in order to perform this operation
deluser <username> <groupname>
Ubuntu
# To delete a group
delgroup <groupname>
Ubuntu

Congratulations!! If you’ve made it till here, you have successfully leant about users and groups, and operations to manage these.

Subscribe to get notified as soon as a blog is released. Stay tuned for more blogs where we will be diving deeper into Linux!!

5860cookie-checkBasics of Linux – Part 1 (User and Group Management)

4 Comments

  1. Avatar gralion torile

    Hello my friend! I want to say that this article is amazing, nice written and include almost all significant infos. I would like to see more posts like this.

  2. Nice and easy to understand blog. Please keep writing.

  3. Thank you so much for giving everyone an exceptionally superb opportunity to read articles and blog posts from this web site. It really is very superb plus jam-packed with a great time for me personally and my office fellow workers to search your website the equivalent of thrice per week to find out the fresh guides you have got. And definitely, we’re actually impressed concerning the very good tactics you give. Selected 4 tips in this post are unequivocally the best we’ve ever had.

Leave a Comment

Your email address will not be published. Required fields are marked *