mix command

User Lock

# passwd -l u1

And to unlock the account, 

# passwd -u u1

greys@s5:~ $ cat /etc/redhat-release    OR  cat /etc/redhat-release OR rpm -qa centos-release

CentOS Linux release 7.4.1708 (Core)

Remote Command

# rdesktop - u Administrator -p "123456" 10.10.10.10

Add User To Root Group - arif

usermod -a -G root arif

Set Date

# date -s "2 MAR 2018 18:00:00"

# date

#   date 041712132018        [ 04 month-17 date-12 hour-13 minute-2018 year ]

[root@mail ~]# date

Tue Apr 17 12:31:57 BDT 2018

---

Sudo Command

# sudo su -

SET hostname

# hostnamectl set-hostname mail

# echo "192.168.0.14 mail.centos7.lan mail " >> /etc/hosts

# cat /etc/hosts

User add

Mail user: adduser -s /bin/false u1     [u1 only mail user]

[root@mail ~]# useradd -m u1 -s /sbin/nologin

[root@mail ~]# passwd u1

User Delete: userdel -r u1

Add a User to Multiple Groups

# useradd -G admins,webadmin,developers tecmint



# useradd -m -c “Ravi Saive, CEO” -s /bin/bash ravi# passwd raviAfterwards, we have to add the user ravi to the file /etc/vsftpd.userlist using the echo command as follows:# echo "ravi" | tee -a /etc/vsftpd.userlist# cat /etc/vsftpd.userlist

Coppy Command

# cp -p /etc/postfix/main.cf{,.bk}

Remote Coppy 

Local to Remote Linux

# scp file.txt remote_username@10.1 0.0.2:/remote/directory          [Local to Remote]

# scp /local/file/path username@example:/remote/path

To copy a directory from a local to remote system, use the -r option

# scp -r /local/directory remote_username@10.10.0.2:/remote/directory

If SSH port: 2322

# scp -P 2322 file.txt remote_username@10.10.0.2:/remote/directory

Remote TO Local Linux:  SCP

Copy a Remote File to a Local System using the scp ommand                  [Remote To Local]

# scp remote_username@10.10.0.2:/remote/file.txt /local/directory

# scp -r username@example.com:/remote/path/to/directory /local/path

/home/mamun/Maildir/cur              [mail inbox ]

/home/mamun/Maildir/.Sent/cur    [send mail]

                       remote server IP                                 TO        own server  

scp -r root@203.169.11.254:/home/u1/Maildir/new/*  /home/u1/Maildir/new/

                        Remote server IP                                 TO        own server 

scp -R root@worldcm.net:/home/kamal/Maildir/cur/*  /home/u1/Maildir/cur/                        --> # inbox mail [ mail show Runing Time]

chown -R u1:u1 /home/u1/Maildir/cur/               -->#[own server] 

scp -R root@worldcm.net:/home/kamal/Maildir/.Sent/cur/*  /home/u1/Maildir/.Sent/cur/       --> # sent mail

scp -R root@worldcm.net:/home/kamal/Maildir/cur/*.*  /home/u1/Maildir/cur/

Windows

scp -r root@203.82.196.18:/etc/postfix /root/f/      [ Remote linux pc ]

scp -r root@203.82.196.18:/etc/postfix/*.* /root/f/      [ Remote linux pc ]

D:\>pscp.exe C:\Users\Administrator\Desktop\tINKERBWL.txt root@192.168.80.77:/root/f    [windows to Linux]

D:\>pscp.exe -r root@192.168.80.77:/root/f C:\Users\Administrator\Desktop\                         [Linux to windows]

Download pscp.exe: http://the.earth.li/~sgtatham/putty/latest/x86/pscp.exe

cd /f/postfix                        [Local pc]

cp -r * /etc/postfix

[root@localhost ~]# openssl passwd -crypt AAAAAKa1234

VCX97jg6iZebc

useradd -m -p <password> -s /sbin/nologin <user>

# useradd -m -p Bay1cN04XNI0M -s /sbin/nologin u4

[root@localhost ~]#  openssl passwd -crypt aaaaka123ssss

2J1oG/L2VPdXc

useradd -m -p <password> -s /sbin/nologin <user>

# useradd -m -p Bay1cN04XNI0M -s /sbin/nologin u4

Change Linux User’s Password in One Command Line

# echo -e "linuxpassword\nlinuxpassword" | passwd linuxuser

# echo "linuxpassword" | passwd --stdin linuxuser

# echo "abc1234" | passwd --stdin arif

User Lock

# passwd -l u1

And to unlock the account, 

# passwd -u u1

UID change centos -7

#  vi /etc/login.defs

--------------------

Startup Script

touch /var/lock/subsys/local

route add -net 192.168.0.0 netmask 255.255.254.0 gw 192.168.30.1     # [Add local IP static route]

Linux User Passwd

# cut -d : -f 1 /etc/passwd

# awk -F":" '{print "Login:" $1 "\tName:" $5 "\tHome:" $6}' /etc/passwd

Display only home directory users

# getent passwd | grep '/home' | cut -d: -f1 | more

Listing Users that Can Login to the System:

#  getent passwd | egrep -v '/s?bin/(nologin|shutdown|sync|halt)' | cut -d: -f1

# yum install colordiff

# yum install wdiff               [On CentOS/RHEL/Fedora]

# dnf install wdiff                 [On Fedora 23+ version]

# sudo apt-get install wdiff  [On Debian/Ubuntu/Mint]

 vim -d file1 file2

 diff -y file1 file2

 grep -Fxvf file1 file2 > file3

 grep -xvFf file2.txt file1.txt #[Find what is missing in file2.txt from file1.txt]

 diff -u file1 file2 > file3

 diff file1 file2 | grep "<" | sed 's/^<//g' > file3

 sort file1 file2 | uniq -u > file3

 sort file1 file2 | uniq -d > file3

---------------------------------------

samba user password

# smbpasswd -a u1

ftp userpassword

 useradd -d /var/ftp/pub/mail u1

Line single search in file

# cat single.txt | grep "adress=10.1.1.10"* | grep "comment"

Create a symbolic link relative to the current directory

[root@mail /]# ln -s /home /var/ftp/pub/mail

cd /home

chmod -R 755 home

Change the default SSH port

# vi /etc/ssh/sshd_config

Port 50683

# /etc/init.d/ssh restart

Verify SSH is listening on the new port by connecting to it. Note how the port number now needs to be declared.

# ssh username@hostname.com -p 50683

----------------------------

File or Folder Count

#  ls -l | grep -v ^l | wc -l

#  ls | wc -l               number of files in a directory.

Mail Disk space

df -h

du -h --max-depth=1

# du -hs /home/temp/

2.4M /home/temp/

du -h public_html/ --max-depth=1

8.0K public_html/_vti_txt

8.0K public_html/_vti_cnf

257M public_html/storage

# du -h public_html/ --max-depth=1 | grep G

5.0G public_html/images

5.5G public_html/

cd /home/ftpadmin/

#cd /home

#du -h --max-depth=1

#du -h --max-depth=1 | sort

#du -h --max-depth=1 | grep career

#cd /home

#du -h --max-depth=1 | grep career

#du -h --max-depth=1 | grep shadin

#du -h --max-depth=1 | grep G

#exit

Find Large Files in Linux

top largest files in Linux

# find / -type f -exec du -sh {} 2>/dev/null + | sort -rh | head -n 10

 largest files with a specific extension in Linux

# find / -type f -iname "*.deb" -exec du -sh {} + | sort -rh | head -10

largest directories and files in Linux

# du -ah /* 2>/dev/null | sort -rh | head -n 10

 top largest directories in Linux

# du -sh /*/ 2>/dev/null | sort -rh | head -n 10

check the size of the sub-directories of a given directory, in this case we’ll use the directory ‘var’

# find /var/* -type d -exec du -sh {} 2>/dev/null + | sort -rh | head -n 10

yum remove without dependencies

# rpm -e --nodeps dovecot

TCP wrapper

[root@ns1 ~]# vi /etc/hosts.allow

------------------------------

LL: localhost

ALL: 127.0.0.1

ALL: 102.22.200.43

ALL: 192.168.

ALL: 192.168.0.0/23

ALL: 102.22.192.29

sshd: 102.22.200.43.145.145 102.161.189.29 102.12.192.0/255.255.255.0 192.168.

ipop3d: ALL

imapd: ALL

                                      --------------------------------------

ALL: localhost

ALL: 127.0.0.1

ALL: 102.22.200.43

ALL: 192.168.

ALL: 192.168.0.0/23

ALL: 102.22.192.29       [server ip]

sshd: 202.22.200.43 203.82.199.2 202.22.192.34 203.76.145.147 203.76.145.146 203.76.145.145 202.161.189.29 202.22.192.0/255.255.255.0 192.168.

ipop3d: ALL

imapd: ALL

                                      ---------------------------------

[root@monitor ~]#   vi /etc/hosts.allow 

#

ALL: 127.0.0.1

ALL: localhost

ALL: 202.22.200.43

ALL: 203.82.199.131

sshd: 203.82.193.34 103.20.140.18 103.20.140.22 202.22.200.43 202.161.189.29 202.22.192.61 202.22.192.0/255.255.255.0 203.76.151.155 203.82.199.0/255.255.255.0 203.82.200.0/255.255.255.0 192.168.80. 192.168.81.

vsftpd: ALL

[root@monitor ~]#  vi /etc/hosts.deny 

#

ALL: ALL

                                     ------------------------------------

[root@ns1 ~]# vi /etc/hosts.deny

ALL: ALL

                        -----------

[root@mail ~]# vi /etc/resolv.conf

nameserver 103.20.140.18

nameserver 202.22.200.44

nameserver 8.8.8.8

---------------------------------------------------------------------------

# yum install epel-release

Install epel on CentOS 5

 wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm rpm -ivh epel-release-latest-5.noarch.rpm

Install epel on CentOS 6

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm rpm -ivh epel-release-latest-6.noarch.rpm

Install epel on CentOS 7

 wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -ivh epel-release-latest-7.noarch.rpm

LAN/WAN

#mii-tool   [ show Conned LAN]

#yum install iptraf

#iptraf        [ Lan Traffic]   

#mii-tool

yum -y install epel-release

yum -y install iptraf htop iftop

yum -y install setuptool

yum -y install system-config*

yum -y install system-config-network-tui     [ RMM ]

yum -y install  openssh*

#system-config-network  [LAN configure]

#setup

# yum --enablerepo=rpmforge install htop

# htop                              [ show proess view]

# yum -y install iftop

yum -y install epel-release

yum -y install iptraf htop iftop setuptool system-config* openssh* system-config-network-tui mutt mlocate quota* net-tools openssl yum-utils yum-priorities ntsysv wget ntp* tzdata vim*

[Centos6]

wget http://pkgs.repoforge.org/iftop/iftop-0.17-1.el6.rf.x86_64.rpm         

rpm -ivh iftop-0.17-1.el6.rf.x86_64.rpm

[Centos 7]

rpm -i http://mirror.pnl.gov/epel/7/x86_64/i/iftop-1.0-0.7.pre4.el7.x86_64.rpm

# iftop -i eth0

Pass the -b option to turn off display bar graphs of traffic:

# iftop -b -i eth0

Pass the -B option to display bandwidth rates in bytes/sec rather than bits/sec:

# iftop -B -i eth0

yum --enablerepo=rpmforge install aria2       [like wget or download tools]

Download from WEB

# aria2c http://releases.ubuntu.com/12.10/ubuntu-12.10-server-i386.iso

Download from Two sources

# aria2c http://releases.ubuntu.com/12.10/ubuntu-12.10-server-i386.iso http://releases.ubuntu.com/12.10/ubuntu-12.10-server-amd64.iso

Download using Two connections

# aria2c -x2 http://releases.ubuntu.com/12.10/ubuntu-12.10-server-i386.iso

Download from BitTorrent

# aria2c http://releases.ubuntu.com/12.10/ubuntu-12.10-server-i386.iso.torrent

Set Download Speed Limit

# aria2c –max-download-limit=100K http://releases.ubuntu.com/12.10/ubuntu-12.10-server-i386.iso

# yum --enablerepo=rpmforge install htop

#htop                              [ show proess view]

ps faux

pgrep kthrotld

ps aux | grep kthrotld

pidof kthrotld

kill -9 9734 9747 9762

# pkill kthrotld

# killall -9 yum

# kill -STOP htop

yum install setuptool -y yum install system-config-network* -y yum install system-config-firewall* -y yum install system-config-securitylevel-tui -y yum install system-config-keyboard -y yum install ntsysv -y

LAN down/up

[root@ns1 ~]# ifdown eth0

[root@ns1 ~]# ifup eth0

[root@ns1 ~]# service network restart

Time Service (NTP)

# yum -y install ntp ntpdate ntp-doc

yum -y install ntp 

# chkconfig ntpd on

# ntpdate pool.ntp.org

#/etc/init.d/ntpd start

# vim /etc/ntp.conf 

server 203.82.199.131

server 116.193.121.44

server 0.oceania.pool.ntp.org    [ add this IP]

server 1.oceania.pool.ntp.org

server 2.oceania.pool.ntp.org

server 3.oceania.pool.ntp.org

chkconfig ntpd on

ntpdate pool.ntp.org

service ntpd start

------------------------------

# yum install tcpdump

1. Capture Packets from Specific Interface

# tcpdump -i eth0

2. Capture Only N Number of Packets

# tcpdump -c 5 -i eth0

4. Display Available Interfaces

# tcpdump -D

8. Capture IP address Packets

# tcpdump -n -i eth0

9. Capture only TCP Packets.

# tcpdump -i eth0 tcp

10. Capture Packet from Specific Port

# tcpdump -i eth0 port 22

11. Capture Packets from source/destination IP

# tcpdump -i eth0 port 22

# tcpdump -i eth0 src 192.168.0.2

-----------------------------------------------

How to stop a currently running cron job process

Compare two files line by line and generate the difference in another file

01

JUN

#   echo "0" > /proc/sys/vm/drop_caches

Clear Swap Space

# swapoff -a && swapon -a

# echo 3 > /proc/sys/vm/drop_caches && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'

OR

$ su -c "echo 3 >'/proc/sys/vm/drop_caches' && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'" root

                   ------------------X----------------------------

shell script clearcache.sh

# vi clearcache.sh

#!/bin/bash # Note, we are using "echo 3", but it is not recommended in production instead use "echo 1" echo "echo 3 > /proc/sys/vm/drop_caches"

# chmod 755 clearcache.sh

# crontab -e

0 2 * * * /path/to/clearcache.sh

 ‘crontab -e’ 

#  crontab -l

0 * * * * sync; echo 3 > /proc/sys/vm/drop_caches

                      -------------------------------X-----------------------------

 Clear log file

# du -h /var/log/

99M munin-node.log

1.5G munin-update.log

# cd /var/log/

# cat /dev/null > munin-update.log

# du -h *

99M munin-node.log

0M munin-update.log

# du -sh access.log

# > access.log

# cat /dev/null > access.log

# echo > access.log

# > /var/log/mail.log

for RHEL/CENTOS:   TIME  

Assuming you have the default or current timezone as UTC and you would like to change it to Singapore timezone

# sync; echo 3 > /proc/sys/vm/drop_caches

# sync; echo 2 > /proc/sys/vm/drop_caches

# sync; echo 1 > /proc/sys/vm/drop_caches

To find which process currently running..

# top

To stop a currently running cron job process.

# pkill process-name   (or)

# pkill 1234

       -------------------------------

clear Swap Memory in Linux / CentOS / RHEL

#  free -h

[root@freelinux etc]# date Thu Sep 6 23:15:06 UTC 2012  [root@freelinux etc]# rm /etc/localtime

Note: All timezones can be found under the directory /usr/share/zoneinfo

Link the Singapore file under the Asia to the /etc/localtime

#cd /etc #ln -s /usr/share/zoneinfo/Asia/Singapore localtime #date Fri Sep 7 07:17:20 SGT 2012

This localtime symbolic links can be overwritten when you execute tzdata-update which will based from /etc/sysconfig/clock settings configured

Example:

current date in Singapore time, you execute the tzdata-update, it will read the /etc/sysconfig/clock file

[root@freelinux etc]# cat /etc/sysconfig/clock ZONE="Asia/Seoul" UTC=true ARC=false [root@freelinux etc]# date Fri Sep 7 07:26:12 SGT 2012 [root@freelinux etc]# tzdata-update [root@freelinux etc]# date Fri Sep 7 08:26:20 KST 2012

For Ubuntu/Debian, the above method will also work. But it also has some commands to make you life easier, see items 1 & 2

1. A simple way to change your timezone is using the “tzconfig” command which will prompt you with a list of region and cities. It will a simple way to update the link /etc/localtime to point to the correct timezone in /usr/share/zoneinfo

[root@freelinux etc]# tzconfig

2.Another way is using the command “dpkg-reconfigure tzdata”. It will be a menu-based type of configuration screen.

[root@freelinux etc]# dpkg-reconfigure tzdata

3. Another method which will work with other distribution as well is via the TZ environment variable

[root@freelinux ~]# date Fri Sep 7 07:46:09 SGT 2012 [root@freelinux ~]# export TZ=Asia/Manila [root@freelinux ~]# date Fri Sep 7 07:46:30 PHT 2012

4. Another way is via “tzselect” command

[root@freelinux ~]# tzselect 

######################################################################################################

Centos 6/RHEL install and use Tzdata time zone utilty

Tzdata is a collection of the worlds time zone information and can be used to set the time for individual users on a Linux system.

To use it first download the tzdata package from the repo.

$ sudo yum -y install tzdata

$ tzselect

Please identify a location so that time zone rules can be set correctly.

Please select a continent or ocean.

1) Africa

2) Americas

3) Antarctica

4) Arctic Ocean

5) Asia

6) Atlantic Ocean

7) Australia

8) Europe

9) Indian Ocean

10) Pacific Ocean

11) none - I want to specify the time zone using the Posix TZ format.

#? 

Centos 6/RHEL install and use Tzdata time zone utilty

Tzdata is a collection of the worlds time zone information and can be used to set the time for individual users on a Linux system.

To use it first download the tzdata package from the repo.

$ sudo yum -y install tzdata

$ tzselect

Please identify a location so that time zone rules can be set correctly.

Please select a continent or ocean.

1) Africa

2) Americas

3) Antarctica

4) Arctic Ocean

5) Asia

6) Atlantic Ocean

7) Australia

8) Europe

9) Indian Ocean

10) Pacific Ocean

11) none - I want to specify the time zone using the Posix TZ format.

#? 

Disabling the GUI login mode of Redhat or CentOS servers

For CentOS 6 or RHEL 6

Edit /etc/inittab, enter:

# nano /etc/inittab

Find:

id:5:initdefault:

Replace with:

id:3:initdefault:

Save and close the file.

For stopping the currently running GUI session:

# init 3

To get back into the GUI mode temporarily, type the following in the terminal.

# init 5

For RHEL 7 or CentOS 7

To see default

systemctl get-target 

To switch GUI off (equivalent to init 3 in the previous versions)

systemctl set-target multi-user.target 

To Enable GUI (equivalent to init 5 in the previous versions)

systemctl set-target graphical.target

For RHEL 8 or CentOS 8

To see default

systemctl get-target 

To switch GUI off (equivalent to init 3 in the previous versions)

systemctl set-target multi-user.target 

To Enable GUI (equivalent to init 5 in the previous versions)

systemctl set-target graphical.target

----

----