Sunday 19 February 2023

Linux Basic Commands - Tips and Tricks

#find the file responsible for ssh

which ssh


rpm -qf /usr/bin/ssh

#find the rpm file and search for the config file.

rpm -qa | grep ssh

rpm -ql openssh-server-8.7p1-28.el9.x86_64

#set the port number

sudo vim /etc/ssh/sshd_config

#Port 22

systemctl reload sshd

#if not working disable SELinux

sudo cat /var/log/secure


setenforce 0

systemctl reload/start sshd

#deny user

sudo vim /etc/ssh/sshd_config

DenyUsers tom

#list files with size

du -sch * | sort

du -sch * | sort -rn

du -sch * | sort -rn | head

#check the open port on the server

nmap -A

#to print all files in dir except 1st and 2nd files:  

ls -l | sed '1,3d'

#for deleting before 15 days file

find path_name -type f -mtime -15 -exec rm -rf {} +

#largest file in the directory

ls -lhS

ls -lhS | awk "NR==2"

#to delete blank lines of a file

sed  -i '/^$/d' file_name

#find a file with particular permission

sudo find /home/devops/ -type f -perm 775

#to see the hard-linked files in different locations

find / -xdev -samefile /tmp/abc.txt

sudo find / -xdev -inum 17375669

#to see the hard-linked files in pwd

ls -li

find -type f -links +1

 sudo find /home/devops/test/ -xdev -type f -links +1 -ls | sort -n

#7 fields in the password file

tail -n1 /etc/passwd


username:password hash:userid:groupid:info about user:home path: user shell

#reset tom user password, next login time

sudo chage -l tom

chage -d 0 tom

#change the shell of a user

tail -n1 /etc/passwd


sudo usermod -s /bin/bash tom

 cat /etc/passwd | grep tom


#change the home directory for a user

cat /etc/passwd | grep tom


sudo mkdir --mode=700 /opt/tom

sudo chown tom:tom /opt/tom/

sudo usermod -d /opt/tom tom

cat /etc/passwd | grep tom


#change the default home directory for the future user

sudo vim /etc/default/useradd


sudo useradd nik

cat /etc/passwd | grep nik


blkid - It can determine the type of content (e.g., filesystem or swap) that a block device holds.

lsblk - list block devices

No comments:

Post a Comment