sudo su -
-
Check if username exists:
id username
-
Add new user with username:
sudo adduser username
-
Check if user has expiry date:
sudo chage -l username
-
Make account expire at specific date:
sudo chage -E 2021-04-15 username
-
Check root login status on direct SSH:
sudo cat /etc/ssh/sshd_config | grep PermitRoot
-
Disable root login on direct SSH: Edit file:
sudo vi /etc/ssh/sshd_config
. Replace the#PermitRootLogin yes
toPermitRootLogin no
. Restart SSH service:sudo systemctl restart sshd && systemctl status sshd
-
Passwordless sudo for user: Edit sudo config
sudo visudo
. Look for line:root ALL=(ALL) ALL
and add line:username ALL=(ALL) NOPASSWD:ALL
.
-
List files in current directory:
ls
-
List files in current directory with permission, date and size:
ll
-
Enable service to start at startup:
sudo systemctl enable service_name
-
Disable service to start at startup:
sudo systemctl disable service_name
-
Start service:
sudo systemctl start service_name
-
Stop service:
sudo systemctl stop service_name
-
Status of a service:
sudo systemctl status service_name -l
-
MariaDB log file:
cat /var/log/mariadb/mariadb.log
-
MariaDB failed to start process: Stop mariadb process. Check log file. Use command:
sudo chown mysql:mysql /var/run/mariadb/
-
Domain name resolver file:
cat /etc/resolv.conf
-
Adding new DNS server entry: Add nameserver entry in resolver file like this:
nameserver 8.8.8.8
-
Replace all occurrence of string in file:
sed -i 's/original_text/new_text/g' file_path
-
Search string in file:
cat file_path |grep text_to_search
- Create folder and sub-folders:
mkdir -p foler/subfolder/sub2
-
Change primary group of directory:
chgrp -R group_name dir_path
-
Change directory permission to specific group: First get directory group ID by
ll -lsd path_of_folder
. The group ID is a number after permission.4 drwxr-xr-x 2 root dbadmin 4096 Jun 22 17:29 /dbadmin/data/
here it is 2.chmod -R 2770 folder_path
2 - Special Permission. set group id. 7 - 4+2+1 = 7 (4= read, 2 = write, 1 = execute).User (root) Permission. 7 - 4+2+1 = 7 (4= read, 2 = write, 1 = execute). Group Permission. 0 - Other users.(zero permission).
-
Get default run level:
sudo systemctl get-default
-
Set default run level GUI:
sudo systemctl set-default graphical.target
-
Check status of GUI run level service:
sudo systemctl status graphical.target
-
Start GUI run level service:
sudo systemctl start graphical.target