Restore a Deleted File in Linux

We will learn how to restore delete file in linux

Foremost is not available in any of the CentOS/RHEL repositories, so we’ll need to install it using RPM.

For centos 7 use following command

yum install https://forensics.cert.org/centos/cert/7/x86_64//foremost-1.5.7-13.1.el7.x86_64.rpm -y

For Centos 6 use following command

yum install https://forensics.cert.org/centos/cert/6/x86_64//foremost-1.5.7-13.1.el6.x86_64.rpm -y

Once formost installed let’s try to delete one file and recover it.

Get details of file midnight.jpg which we will delete and recover

file midnight.jpg
md5sum midnight.jpg

Now delete file

rm -f midnight.jpg

Restore a Deleted File

mkdir /root/recover
foremost -i /dev/sda1 -t jpg -o /root/recover/

Here -i used to specify disk and -t used to define type of file which we want to restore.
This command will find any .jpg files in /dev/sda1 and restore them into the /root/restored/ directory, as long as the space they are using on disk has not yet been overwritten by anything else.
Now go to /root/restored/jpg folder and execute md5sum 17602156.jpg and you will find md5 hash of this file is exactly same as that of midnight.jpg.

securing cpanel website

Here we will learn easy command which will correct permission and ownership of all files and folders from cPanel account.

Below is command to correct ownership and permission of all files and folders of cPanel user. To execute this command you need root user access.

Suppose are securing permission and ownership of cPanel user midnight. Then commands will be.

Correcting ownership of home directory

chown midnight.midnight /home/midnight

Command to set secure permission for home directory of cPanel user midnight

chown 711 /home/midnight

Following command will find all files and set secure permission as 644.

cd /home/midnight/public_html;find ./ -type f -exec chmod 644 "{}" \;

Now find all folders and set secure permission as 755

cd /home/midnight/public_html;find ./ -type d -exec chmod 755 "{}" \;

Above command will set 755 permission to public_html folder as well. But recommended permission for public_html folder is 750

cd /home/midnight/public_html;chmod 750 ../public_html

Now correcting ownership of all files and folders stored in public_html

cd /home/midnight/public_html;chown midnight.midnight ../public_html -R

Then correct ownership of public_html folder using command

cd /home/midnight/public_html;chown midnight.nobody ../public_html

You have set secure permissions and ownership to all files and folders for cPanel account midnight.

Open port using Firewalld

How to open port using firewalld command

To open specific port say 101 use following command

firewall-cmd --permanent --add-port=101/tcp

Then execute following command to reload firewalld service.

firewall-cmd reload

To remove opened port –remove-port as given below

firewall-cmd --permanent --remove-port==101/tcp
firewall-cmd --reload

Command to list ports opened in firewalld.

firewall-cmd --list-ports

How to open port range say 300-400 in firewalld

firewall-cmd --permanent --add-port=300-400/tcp
firewall-cmd --reload

Following command will list services whose ports are open

firewall-cmd --list-services

To open port of specific service command would be

firewall-cmd --permanent --add-service=http

To remove port of specific service command would be

firewall-cmd --permanent --remove-service=http