Michael Dudli

Michael Dudli

Cloud Specialist with more than 10 years experience in the Hosting Business. Website URL: http://www.cloudserver24.com

How to use PS, Kill & Nice in Linux to manage processes

  • Published in Basics

 

Processes in Linux have extreme critical importance as every task and application running on your server is a process and sometimes processes stuck and can cause a system crash so to save your server, you have to identify the stuck process and kill the process before it kills your server and prove to be disastrous for you

To check how many process are running on Linux you can use the top command but ps command with combinations can also give you a good picture

#ps aux 

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

root         1  0.0  0.2  24188  2120 ?        Ss   14:28   0:00 /sbin/init

root         2  0.0  0.0      0     0 ?        S    14:28   0:00 [kthreadd]

root         3  0.0  0.0      0     0 ?        S    14:28   0:00 [ksoftirqd/0]

root         6  0.0  0.0      0     0 ?        S    14:28   0:00 [migration/0]

root         7  0.0  0.0      0     0 ?        S    14:28   0:00 [watchdog/0]

root         8  0.0  0.0      0     0 ?        S<   14:28   0:00 [cpuset]

root         9  0.0  0.0      0     0 ?        S<   14:28   0:00 [khelper]

lets suppose we want to grep a process in all of these processes 

#ps aux | grep khelper

This will give you only one process khelper

Now we want to kill the process as it’s stuck so we can use following commands to kill it

#kill 9 (9 is the PID of khelper)

#pkill -9 khelper

#killall khelper

All of these commands will kill khelper in their own way

Now if you want to run a program with a certain value use the command nice. High priority processes are less nice and low priority process are nicer as they consume less resources of server

Let’s say I want to run uptime command with priority 5

#nine –n 5 uptime

 

How to use AWK

 

In this post we will see how to use "awk" which is an important thing when it comes to scripting as almost all the scripts in bash use "awk"

Normally awk is used with print and in any command we can print the part of the command we need through awk 

If we want to print number of logged in users in machine we know that we use the uptime command 

# uptime

01:03:00 up 1 day, 23:06,  2 users,  load average: 0.01, 0.05, 0.01

Now we want to print the sixth part which is the number of users so we will use 

# uptime | awk ' { print $ 6}'

2

It will show the result as "2"

awk can also used with -F which is known as field separator 

Like if we want to see all the users in linux we have /etc/passwd file 

# awk -F ":" '{print "username: " $1 }' /etc/passwd

It will produces results like following 

username: abrt

username: haldaemon

username: saslauth

username: postfix

username: ntp

username: apache

username: avahi

username: pulse

username: gdm

username: sshd

username: tcpdump

username: ahmed

You can print out multiple things in one line with awk 

#  awk -F ":" '{print "username: " $1  " Path: " $6}' /etc/passwd

It will show results like this 

username: haldaemon Path: /

username: saslauth Path: /var/empty/saslauth

username: postfix Path: /var/spool/postfix

username: ntp Path: /etc/ntp

username: apache Path: /var/www

username: avahi Path: /var/run/avahi-daemon

username: pulse Path: /var/run/pulse

username: gdm Path: /var/lib/gdm

username: sshd Path: /var/empty/sshd

username: tcpdump Path: /

username: ahmed Path: /home/ahmeda

How to take backups & restore backups in MySQL server

  • Published in MySQL

 

In this post we will discuss how to take and restore backups of MySQL database.

You can load a dump back into a database also

Take dump of the database by the following command

#mysqldump -u(username) -p(password) (databasename) > cacti.sql

Here cacti.sql is the backup file which will be the backup of my database 

Now if you want to restore the database you have to first make a database then load this file into the newly made database 

#mysql -u(username) -p(password)

> create database cacti;

>quit

Now a database named cacti is created and you can restore the dump by the following command

mysql -u(username) -p(password) cacti < cacti.sql

If you want just the structure dump of a database then following command will be used

#mysqldump -u(username) -p(password)  --no-data (databasename) > cacti.sql

*Here cacti is the newly created database in which we have loaded the backup dump

How to Secure SSH in Linux Server

 

Technology is a rapid growing field and as fast as its moving the more is the chance to get attacked by people who are known by a word name hackers. By default Linux SSH port is 22 but as everyone knows the standard port so following are some important tips for you to secure your SSH.

Change your SSH port

To change your SSH port you have to go to file

#vi /etc/ssh/sshd_config

Search for the line with Port and if its commented the uncomment it and use your custom port for SSH

 

Disabling Root Login

If you want the hacker to stop entering your system then it’s a great function of Linux to disable root login as everyone tries to get maximum privileges to access your serve. So search for the line PermitRootLogin and change it to NO but you have to add a user first who will access the server for it use the following commands

#adduser Michael

#passwd Michael

New Password: “Enter your password”

Lastly enter the following line in your config 

AllowUsers Michael

Since you have disabled root so you want Michael for root privileges by the following command

#vi /etc/sudoers

Michael  ALL=(all)ALL

Now restart the ssh services by the following command

#/etc/init.d/sshd restart

Last step is that you need to make some changes in your iptables

iptables -t filter -A INPUT -p tcp --dport 6060 -j ACCEPT

here 6060 is your custom port

Now to access your server you need the following command

Ssh –p6060 Michael@IP_Address

 

Subscribe to this RSS feed