Add, Delete, and Update Accounts in Ubuntu from Terminal

Single user account on a shared computer can be a security issue? Using multiple user accounts in Ubuntu is a powerful way to improve both security and workflow organization. Separating work documents from personal files, restricting access to sensitive data for different users, and simplifying collaboration with colleagues. Most importantly, using a single root account for everyday tasks creates a significant security risk. Accidental data deletion or accidental compromised program installation with root privileges could have devastating consequences.

Adding new user

Set your username.


sudo adduser username


When adding new user you can just add the password and skip other requirements like complete name and address and other things if thats not necessary for you.

Removing user


sudo userdel username


Delete everything of the user including files


sudo userdel -r username


Grant the user sudo privilege ( user can install and and change everything)


sudo usermod -aG sudo username


To remove sudo privilege


sudo deluser username sudo


Update username of a user


sudo usermod -l newname previousname


How to generate requirements.txt in python

A requirements.txt file is essential for managing Python project dependencies. It ensures everyone working on your project has the correct libraries installed for development and deployment.

The simplest way or automatically generate requirements.txt is using piprequs library. It will generate requairements.txt file based on the imports of your project.

First install the library


pip install pipreqs



Navigate to Your Project
In your terminal, open the root directory of your Python project.
( the folder where your python project script located)

And then run this command


pipreqs .


This tool will scan your project’s codebase for import statements and generate a list of required packages.


Later when you need to install your project dependency then just run


pip install -r requirements.txt


How to add or remove a directory in ubuntu

Creating the directory


mkdir directory_name


If the path is protected we need to use sudo command

sudo mkdir dicrectory_name

Removing the directory


rmdir directory_name


If the path is protected we need to use sudo command

sudo rmdire dicrectory_name

Remove the directory including items permanently


rm -r directory_name


More

Make sure you understand the commands actions . Then run the command. Because this can delete all the files and delete files.

Delete All Fills of a directory. Open terminal in that directory and run this command


rm -rf *


Or you can specify the path like this

rm -rf ~/Documents/my_folder/*

it will delete all the files of my_folder

Deleting Specific Folder of a Directory


rm -rf my_folder


One of useful deleting feature. Delete files using the file extension like .mp4 or .txt or like this . Open terminal in that directory.

rm -f *.txt

Or you can specify the directory path


rm -f ~/Documents/my_folder/*.txt


Nginx: Essential Commands

Frequently used commands

Install Nginx


sudo apt-get install nginx



Start And Stop Nginx server

Start


sudo systemctl start nginx


Stop


sudo systemctl stop nginx



Current Status


sudo systemctl status nginx



Restart And Reload

Restart


sudo systemctl restart nginx


Reload


sudo systemctl reload nginx



Enable Or Disable

Enable(Start Automatically)


sudo systemctl enable nginx


Disable( Stop automatic Start On booting)


sudo systemctl disable nginx



Completely remove nginx


sudo apt-get purge nginx nginx-common nginx-full



Test Configuration


sudo nginx -t



Related

Add symbolic link


sudo ln -s  /etc/nginx/sites-available/your-server etc /etc/nginx/sites-enabled


Clean cache


sudo apt-get autoclean
sudo apt-get autoremove