30 Step Server
30 Step Server
We have already covered a detailed instructions on how to register and active RedHat
subscription at the below guide.
But as I said we will be using ip command to configure static IP address. So, make sure you first
check the current IP address.
# ip addr show
Now open and edit file /etc/sysconfig/network-scripts/ifcfg-enp0s3 using your choice of
editor. Here, I’m using Vi editor and make sure you must be root user to make
changes…
# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
Now we will be editing four fields in the file. Note the below four fields and leave
everything else untouched. Also leave double quotes as it is and enter your data in
between.
After making the changes ‘ifcfg-enp0s3‘, looks something like the image below. Notice
your IP, GATEWAY and DNS will vary, please confirm it with your ISP. Save and Exit.
Network Details
Restart service network and check the IP is correct or not, that was assigned.
If everything is ok, Ping to see network status…
After restarting network, make sure to check the IP address and network
status…
# ip addr show
Verify IP Address
# echo $HOSTNAME
# vi /etc/hostname
After setting hostname, make sure to confirm hostname by logout and login
again. After login check new hostname.
$ echo $HOSTNAME
Confirm New Hostname
Alternatively you may use command ‘hostname‘ command to view your current
hotsname.
$ hostname
Important: You can also run the below command which will not prompt for the packages update
and you do not need to type ‘y‘ for accepting the changes.
However it is always a good idea to review the changes which is going to take place on the
sever specially in production. Hence using the below command may automate the update and
upgrade for you but it is not recommended.
If you would like to change default port (80) of Apache HTTP Server to any
other port. You need to edit the configuration file ‘/etc/httpd/conf/httpd.conf‘ and
search for the line that starts typically like:
LISTEN 80
Change port number ‘80‘ to any other port (say 3221), save and exit.
# firewall-cmd --add-service=http
Reload firewall.
# firewall-cmd --reload
After making all above things, now it’s time to restart Apache HTTP server, so
that the new port number is taken into effect.
Now verify the Apache HTTP Server by using links command line tool as
shown in the below screen.
# links 127.0.0.1
7. Install PHP
PHP is a server-side scripting language for web based services. It is
frequently used as general-purpose programming language as well. Install
PHP on CentOS Minimal Server as.
After installing php, make sure to restart Apache service to render PHP in
Web Browser.
Next, verify PHP by creating following php script in the Apache document root
directory.
# echo -e "<?php\nphpinfo();\n?>" > /var/www/html/phpinfo.php
Now view the PHP file, we just created (phpinfo.php) in Linux Command Line
as below.
# php /var/www/html/phpinfo.php
OR
# links http://127.0.0.1/phpinfo.php
Verify PHP
# firewall-cmd --add-service=mysql
# /usr/bin/mysql_secure_installation
# SSH -V
Protocol 2 (Now)
Disable SSH ‘root login‘ and allow to connect to root only after login to normal
user account for added additional Security. For this, open and edit
configuration file ‘/etc/ssh/sshd_config‘ and change PermitRootLogin
yes t PermitRootLogin no.
# java -version
# /usr/sbin/tomcat version
Add service tomcat and default port (8080) through firewall and reload
settings.
# firewall-cmd --reload
Now it’s time to secure tomcat server, create a user and a password to access
and manage. We need to edit file ‘/etc/tomcat/tomcat-users.xml‘. See the section
which looks like:
<tomcat-users>
....
</tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
List all open ports and corresponding services using them on host.
# nmap 127.0.01
You may also use firewall-cmd to list all the ports, however I find nmap more
useful.
# firewall-cmd --list-ports
OR
# firewall-cmd --state
# firewall-cmd --get-default-zone
# firewall-cmd --set-default-zone=work
Swich Firewalld Zones
# firewall-cmd --list-services
# firewall-cmd --add-service=http
# firewall-cmd –reload
# firewall-cmd --reload
# firewall-cmd --remove-service=http
# firewall-cmd --reload
# firewall-cmd --reload
# firewall-cmd --add-port=331/tcp
# firewall-cmd --reload
# firewall-cmd --reload
# firewall-cmd --remove-port=331/tcp
# firewall-cmd --reload
# firewall-cmd --reload
To disable firewalld.
# systemctl stop firewalld
# firewall-cmd --state
To enable firewalld.
# firewall-cmd --state
For more usage and practical examples on how to use wget command to
download files on the terminal, read 10 Wget Command Examples.
Telnet also very useful for checking listening ports on remote computer or
host.
# yum install telnet
# telnet google.com 80
# wget http://prdownloads.sourceforge.net/webadmin/webmin-1.740-1.noarch.rpm
Install Webmin
After webmin installation, you will get a message on terminal to login to your
host (http://ip-address:10000) using your root password on port number
10000. If running a headless server you can forward the port and access it on
a machine/server that is headed.
Attention! Extra care is needs to be taken while adding Third Party Repository.
After installing ntfs-3g has been installed, you can mount Windows NTFS
partitions (where /dev/sda5 is my windows drive) using following command.
# mount -ro ntfs-3g /dev/sda5 /mnt
# cd /mnt
# ls -l
# vi /etc/vsftpd/vsftpd.conf
Edit a few fields and leave other as it is, unless you know what you are doing.
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
You may also change the port number and open vsftpd port through the
firewall.
# firewall-cmd --add-port=21/tcp
# firewall-cmd --reload
# visudo
sudoers File
Give all the permission (equal to root) to a user (say tecmint), that has already
been created.
tecmint ALL=(ALL) ALL
Give all the permission (equal to root) to a user (say tecmint), except the
permission to reboot and shutdown the server.
Again open the same file and edit it with the below contents.
Give permission to a group (say debian) to run a few root privilege command
say (add user and delete user) .
# setenforce 0
# setenforce 1
Run rkhunter as a scheduled job, from a script file or manually to scan harmful
exploits in Linux.
# rkhunter --check
Crontab Fields
30 4 * * *
speedtest-cli
30 4 * * * /home/$user/script.sh
After adding the above line to crontab, it will run automatically at 04:30 am
everyday and the output depends upon what is there in script file. Moreover
script can be replaced by commands. For more examples of cron jobs,
read 11 Cron Jobs Examples in Linux
Our CentOS Minimal server is a headless server. Lets prepare it to host virtual
machines that is accessible over HTTP by installing following packages.
# wget
http://download.virtualbox.org/virtualbox/4.3.12/Oracle_VM_VirtualBox_Extensi
on_Pack-4.3.12-93733.vbox-extpack
# adduser vbox
# passwd vobx
# usermod -G vboxusers vbox
# wget http://sourceforge.net/projects/phpvirtualbox/files/phpvirtualbox-4.3-
1.zip
Extract the zip and copy the extracted folder to HTTP working directory.
# unzip phpvirtualbox-4.*.zip
# cp phpvirtualbox-4.3-1 -R /var/www/html
# mv config.php.example config.php
Open the configuration file to edit and add ‘username‘ and ‘password‘ we just
created in the above step.
# vi config.php
http://192.168.0.15/phpvirtualbox-4.3-1/
First make backup of two files, so that if anything goes bad, you have the
option to revert back. Create a backup of ‘/etc/grub2/grub.cfg‘ as
‘/etc/grub2/grub.cfg.old‘.
# cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.old
# cp /etc/grub.d/10_linux /etc/grub.d/10_linux.old
Now open ‘/etc/grub.d/10_linux‘ and add the below line at the end of the file.
cat <<EOF
set superusers=”tecmint”
Password tecmint avi@123
EOF
# grub2-mkconfig --output=/boot/grub2/grub.cfg
After entering login credentials, you will able to edit grub boot menu.
# grub2-mkpasswd-pbkdf2
Now open ‘/etc/grub.d/10_linux‘ file and add the below line at the end of the file.
cat <<EOF
set superusers=”tecmint”
Password_pbkdf2 tecmint
grub.pbkdf2.sha512**************************************************
EOF
Replace the password with the one generated on your system. Don’t forget to
cross check the password.
Also note you need to generate grub.cfg in this case as well, as described
above. Reboot and next time you press ‘e‘ to edit, you will be prompted for
username and password.