Published March 29, 2018 by

Install Sublime Text 3 in Linux

The popular cross-platform Sublime Text editor finally offers official Linux apt repository to make it easy to install and receive an update in Ubuntu.

Sublime Text is a proprietary source code editor with a Python API. It supports many programming languages and markup languages, and its functionality can be extended by users with plugins.

It’s available to download and use for free, but you’re supposed to buy a license if you plan on using it full-time.


Install Sublime Text in Ubuntu

wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -

sudo apt-get install apt-transport-https

echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

sudo apt-get update

sudo apt-get install sublime-text

Now we can run sublime from an application menu.


Install Sublime Text in Centos/RHEL

# sudo rpm -v --import https://download.sublimetext.com/sublimehq-rpm-pub.gpg
# sudo yum-config-manager --add-repo 
# https://download.sublimetext.com/rpm/stable/x86_64/sublime-text.repo
# sudo yum install sublime-text 

Run Sublime-Text on a terminal

sublime

Uninstall

sudo apt-get remove sublime-text                       # for ubuntu
sudo apt-get autoremove

sudo yum remove sublime-text                           # for centos
sudo yum autoremove
Read More
Published March 26, 2018 by

Set up an Email Alert when a User login in Linux System

This tutorial shows a simple way to know when someone logged in as root or normal user it should send an email alert notification to the specified email address along with the IP address of the last login. So, once you know the IP address of the last login made by an unknown user you can block SSH login of particular IP address on iptables Firewall.

Set up an email alert when a User login in Linux system

First, we need to email utility installed on our server for sending mail, So install email utility using this tutorial.


Set Root Login Email Alerts

Now log in as root user and go to root’s home directory by typing cd /root command.
 # cd /root  
Open .bashrc file. Please remember .bashrc is a hidden file.
 # vim .bashrc  
Add the following line at the bottom of the file. Make sure to replace "ServerKaka" with a hostname of your Server and change "it.subhashpatel@gmail.com" with your email address.
 echo 'ALERT - Root Shell Access (ServerKaKa) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d'(' -f2 | cut -d')' -f1`" it.subhashpatel@gmail.com  

Save and close the file and log out and log back in. Once you log in via SSH, a .bashrc file by default executed and sends you an email address of the root login alert.


Set Normal User Login Email Alerts

Now log in as serverkaka (normal User) user and go to serverkaka’s home directory by typing cd /home/serverkaka command.
 # cd /home/serverkaka  
Open .bashrc file. Please remember .bashrc is a hidden file.
 # vim .bashrc  

Add the following line at the bottom of the file. Make sure to replace "ServerKaka" with a hostname of your Server and change "it.subhashpatel@gmail.com" with your email address.
 echo 'ALERT - Root Shell Access (ServerKaKa) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d'(' -f2 | cut -d')' -f1`" it.subhashpatel@gmail.com  
Save and close the file and log out and log back in. Once you log in via SSH, a .bashrc file by default executed and sends you an email address of the root login alert.
Read More
Published March 24, 2018 by

All Linux Command Line Sheet

System Information
uname -a
Display Linux system information
uname -r
Display kernel release information
cat /etc/redhat-release
Show which version of redhat installed
uptime
Show how long the system has been running + load
hostname
Show system host name
hostname -I
Display the IP addresses of the host
last reboot
Show system reboot history
date
Show the current date and time
cal
Show this month's calendar
w
Display who is online
whoami
Who you are logged in as


Performance Monitoring and Statistics
top
Display and manage the top processes
htop
Interactive process viewer (top alternative)
mpstat 1
Display processor related statistics
vmstat 1
Display virtual memory statistics
iostat 1
Display I/O statistics
tail 100 /var/log/messages
Display the last 100 syslog messages (Use
/var/log/syslog for Debian based systems.)
tcpdump -i eth0
Capture and display all packets on interface eth0
tcpdump -i eth0 'port 80'
Monitor all traffic on port 80 (HTTP)
lsof
List all open files on the system
lsof -u user
List files opened by user
watch df -h
showing periodic updates


User Information and Management
Id
Display the user and group ids of your current user
last
Display the last users who have logged onto the system
who
Show who is logged into the system
w
Show who is logged in and what they are doing
groupadd test
Create a group named "test"
useradd -c "Subhash" -m subhash
Create an account named subhash, with a comment of "Subhash" and create the user's home directory
userdel subhash
Delete the subhash account
usermod -aG it subhash
Add the subhash account to the it group


Files and Directory Commands
ls -al
List all files in a long listing (detailed) format
pwd
Display the present working directory
mkdir directory
Create a directory
rm file
Remove (delete) file
rm -r directory
Remove the directory and its contents recursively
rm -f file
Force removal of file without prompting for confirmation
rm -rf directory
Forcefully remove directory recursively
cp file1 file2
Copy file1 to file2
cp -r source_directory destination
Copy source directory recursively to destination. If destination exists, copy source directory into destination, otherwise create destination with the contents of source directory.
mv file1 file2
Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2
ln -s /path/to/file linkname
Create symbolic link to linkname
touch file
Create an empty file or update the access and modification times of file
cat file
View the contents of file
less file
Browse through a text file
head file
Display the first 10 lines of file
tail file
Display the last 10 lines of file
tail -f file
Display the last 10 lines of file and "follow" the file as it grows


Process Management
ps
Display your currently running processes
ps -ef
Display all the currently running processes on the system
ps -ef | grep processname
Display process information for processname
top
Display and manage the top processes
htop
Interactive process viewer (top alternative)
kill pid
Kill process with process ID of pid
killall processname
Kill all processes named processname
program &
Start program in the background
bg
Display stopped or background jobs
fg
Brings the most recent background job to foreground
fg n
Brings job n to the foreground


Networking
ifconfig -a
Display all network interfaces and ip address
ifconfig eth0
Display eth0 address and details
ethtool eth0
Query or control network driver and hardware settings
ping host
Send ICMP echo request to host
whois domain
Display whois information for domain
dig domain
Display DNS information for domain
dig -x IP_ADDRESS
Reverse lookup of IP_ADDRESS
host domain
Display DNS ip address for domain
hostname -i
Display the network address of the hostname
hostname -I
Display all local ip addresses
netstat -nutlp
Display listening tcp and udp ports and corresponding programs


Archives
tar cf archive.tar directory
Create tar named archive.tar containing directory
tar xf archive.tar
Extract the contents from archive.tar
tar czf archive.tar.gz directory
Create a gzip compressed tar file name archive.tar.gz
tar xzf archive.tar.gz
Extract a gzip compressed tar file
tar cjf archive.tar.bz2 directory
Create a tar file with bzip2 compression
tar xjf archive.tar.bz2
Extract a bzip2 compressed tar file


Installing Packages
yum search keyword
Search for a package by keyword
yum install package
Install package
yum info package
Display description and summary information about package
rpm -i package.rpm
Install package from local file named package.rpm
yum remove package
Remove/uninstall package


Search
grep pattern file
Search for pattern in file
grep -r pattern directory
Search recursively for pattern in directory
locate name
Find files and directories by name
find /home/john -name 'prefix*'
Find files in /home/john that start with "prefix"
find /home -size +100M
Find files larger than 100MB in /home


SSH
ssh host
Connect to host as your local username
ssh user@host
Connect to host as user
ssh -p port user@host
Connect to host using port


File Transfer
scp file.txt server:/tmp
Secure copy file.txt to the /tmp folder on server
scp server:/var/www/*.html /tmp
Copy *.html files from server to the local /tmp folder
scp -r server:/var/www /tmp
Copy all files and directories recursively from server to the current system's /tmp folder
rsync -a /home /backups/
Synchronize /home to /backups/home
rsync -avz /home server:/backups/
Synchronize files/directories between the local and remote system with compression enabled


Hardware Information
dmesg
Display messages in kernel ring buffer
cat /proc/cpuinfo
Display CPU information
cat /proc/meminfo
Display memory information
free -h
Display free and used memory (-h for human readable, -m for MB, -g for GB.)
lspci -tv
Display PCI devices
lsusb -tv
Display USB devices
dmidecode
Display DMI/SMBIOS (hardware info) from the BIOS
hdparm -i /dev/sda
Show info about disk sda
hdparm -tT /dev/sda
Perform a read speed test on disk sda
badblocks -s /dev/sda
Test for unreadable blocks on disk sda


Disk Usage
df -h
Show free and used space on mounted filesystems
df -i
Show free and used inodes on mounted filesystems
fdisk -l
Display disks partitions sizes and types
du -ah
Display disk usage for all files and directories in human readable format
du -sh
Display total disk usage off the current directory


Directory Navigation
cd ..
To go up one level of the directory tree. (Change into the parent directory.)
cd
Go to the $HOME directory
cd /opt
Change to the /opt directory
Read More