CentOS, Ubuntu, Kali Linux Useful Commands

The commands that work on most version of Linux environment are listed below.

1. Identify OS Version

$ lsb_release -a   //Identify exact version of OS

$ uname -a      //Identify 64 or 32 bit version

$ cat /etc/*release*

View Ubuntu Version

2. Identify Open ports

$ sudo lsof -i -P -n

$ sudo lsof -i -P -n | grep LISTEN

 

3. Restart or Reboot server

$ sudo reboot

$ sudo shutdown -r //command restarts server

$ sudo shutdown -r +30 //command restart server in another 30 mins

 

4. Vi Text Editor – How to save the changes and quit the editor?

  1. After making changes, press Esc Key
  2. Press : (colon). You will notice your cursor appearing at the lower left corner of the screen beside a colon prompt.
  3. Enter any of these options as per your need.

wq! = write the changes to file and quit

q! = exit without writing the changes.

w! = write the changes to file without exiting

 

5. Disable IPv6

Step 1: “ip address” command shows that IPv6 is unnecessarily enabled on the interfaces.

server@it:~$ ip 

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:15:7e:46:8d:63 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.2/24 brd 192.168.1.1 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::215:5dff:fe64:8d36/64 scope link
valid_lft forever preferred_lft forever

Step 2:  use editor to add configurations to disable IPv6

server@it:~$ sudo nano /etc/sysctl.conf

net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

Step 3: reload sysctl

server@it:~$ sudo sysctl -p

Step 4: review interfaces

server@it:~$ ip a

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:15:7e:46:8d:63 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.2/24 brd 192.168.1.1 scope global eth0
valid_lft forever preferred_lft forever

 

6. List Status of all installed services

$ service –status-all

 

7. UFW – Uncomplicated Firewall

$ sudo service ufw {status | start | stop | restart | force-reload}

 

8. Purge vs Remove

$ apt remove <package_name>         //Command uninstall the package however the configuration files remain on the system.

$ apt purge <package_name>            //Command uninstall the package and removes all the configuration files except those exist in home folder (/home/bob)

 

9. Get MAC address (2 options)

$ ifconfig -a 

$ ip link

ip link MAC address

10. Release and renew IP address DHCP

$ dhclient -r <interface_name>       // -r to release existing IP address of interface e.g eth0

$ dhclient <interface_name>           // renew IP address for interface e.g. eth0

 

11. Swap

Swap is a temporary hard drive space that operating system can temporarily store data that it can no longer hold in RAM. The swap space on the hard drive is used mainly when there is no longer sufficient space in RAM.

The information written to disk will be significantly slower than information kept in RAM, but the operating system will prefer to keep running application data in memory and use swap for the older data. Overall, having swap space as a fall back for when your system’s RAM is depleted can be a good safety net against out-of-memory exceptions on systems with non-SSD storage available.

To view swap space in your Ubuntu system (2 options

$ sudo swapon –show

$ free -h

Ubuntu Swap Memory

$ sudo swapoff -a           //turn off swap space

$ sudo swapon -a           //turn on swap space

Ubuntu Swap Memory Off

 

12. Change Password

$ passwd       //change password of logged in user

$ passwd  {userName}     //change password of another user

 

13. Install SSH

Before installing SSH, verify if SSH is already present in the server

$ service sshd status    

If not installed, the output is unit sshd.service could not be found, then you can safely proceed with following commands to install open ssh server.

$ sudo apt update 

$ sudo apt install openssh-server

 

14. Install Telnet

In minimal version of Ubuntu, telnet is not found by default. You can install by

$ sudo apt update

$ sudo apt-get install telnet

 

15. Install Ping

In minimal version of Ubuntu, ping is not found by default. You can install by

$ sudo apt update

$ sudo apt install iputils-ping

You may also like...

Thank you for visiting us. To continue receiving updates, please Subscribe to our Social Media Channels.