Useful Linux Commands 

Here is a list of essential Linux commands that are useful for various tasks in system administration, user management, networking, and more. 

1.   VPN Management

1.1      Turn on a VPN Connection (e.g., `VPN1`):

sudo nmcli con up id 'VPN1' --ask

This command activates a VPN connection, prompting for credentials if needed.

1.2      Check VPN Connection Status:

sudo nmcli con show --active | grep 'VPN1'

Use this to verify if the VPN connection `VPN1` is currently active. 

2.   User Management

2.1      Add a New User:

Creates a new user account with the specified username. 

sudo adduser username 

2.2      Add a User to the Sudo Group:

Grants `username` administrative privileges by adding them to the `sudo` group.

sudo adduser username sudo

2.3      Delete a User, Including Home Directory and Mail Spool:

Removes a user and their associated home directory and mail.

sudo userdel -r username 

2.4      List All Users:

Displays a list of all existing users on the system.

cat /etc/passwd

2.5      Kill All Processes of a User:

Terminates all active processes for a specified user.

sudo killall -9 -u username

3.   System Utilities

3.1      Run a Command After a Specified Time:

sleep 1h && ls

This example will execute the `ls` command after a delay of 1 hour.

3.2      Enable SSH on Ubuntu:

Enables SSH, allowing secure remote connections to the system.

sudo apt update

sudo apt install openssh-server

This installs the OpenSSH server, which includes the necessary components to run an SSH server on Ubuntu.

After running these commands, the SSH server usually starts automatically. However, to ensure SSH is enabled and running, you may want to check its status:

 sudo systemctl status ssh

If SSH is inactive, you can start it manually:

sudo systemctl start ssh

And to enable it on boot: 

sudo systemctl enable ssh

4.   File and Directory Management

4.1      Get the Size of Home Subdirectories:

sudo du -sh /home/*

Calculates and displays the size of each subdirectory in the `/home` directory. 

5.   Troubleshooting and System Updates

5.1      Resolve GLIBC Error (`GLIBC_2.29 not found`):

If you encounter the error `/lib/x86_64-linux-gnu/libm.so.6: version 'GLIBC_2.29' not found`, you can install the required library:

sudo apt-get install libgfortran3

Note: `libgfortran3` is unsupported in Ubuntu 20.04. If needed, copy `libgfortran.so.3` from an older Ubuntu version:

sudo su

cd /usr/lib/x86_64-linux-gnu

scp -r username@<remote-IP>:/usr/lib/x86_64-linux-gnu/libgfortran.so.3 .

6.   Process Control

6.1      Pause a Process:

To suspend a process with a specific job ID (e.g., `20419`):

sudo kill -STOP 20419

6.2      Resume a Paused Process:

sudo kill -CONT 20419

7.   Converting Python Scripts to Binaries

You can compile a Python script into a standalone binary file using `PyInstaller`: 

7.1      Upgrade `pip`:

python3 -m pip install --upgrade pip

7.2      Install PyInstaller:

sudo pip3 install pyinstaller

7.3      Compile the Script:

pyinstaller your_script.py

 

The binary file will be generated in the `dist` folder.

University of Kurdistan, Sanandaj logo

Department of Chemistry, Faculty of Science, University of Kurdistan