7-Configure CentOS 8 Primary Server
7-Configure CentOS 8 Primary Server
• During the overall process of configuring the server, you have to login to root user.
• Process of Linux configuration is very complicated, make sure that you follow the configuration process exactly;
do not jump or skip any process.
• Linux configuration are very sensitive, you have to be careful with every single component of syntax and
command such as space, sign, paragraph, etc.
• If you are not sure about the use of any command, you can type: man command_name; EX: man rm
• This academic tutorial is intended for demonstration only, you may use simple passwords here, but in real
practice, you should use strong passwords.
• You can skip the yellow highlight parts.
♦ View the current time zone and make sure that Asia/Phnom_Penh is there
[root@primary ~] # ls -l /etc/localtime
♦ To restart the OS
[root@primary ~] # init 6
or
[root@primary ~] # reboot
♦ Test ICMP service by ping to google.com and make sure it can reach Google domain. Press Ctrl + c to stop.
[root@primary ~] # ping google.com -c10
or
[root@primary ~] # ip a
Remote Login with Password Authentication via Terminal (Mac OS and Linux OS)
From MacOS or Linux OS, use Terminal to remote login to the server.
♦ Make sure both server and client are connected – use the command ping to test connection first
Copy file from CentOS server to CentOS client
♦ Create a test file on CentOS server
[root@primary ~] # touch /root/ServerTestFile1.txt
♦ Copy file from CentOS server to CentOS client user, IP address, directory on client
[root@primary ~] # scp /root/ServerTestFile1.txt [email protected]:/home
♦ Copy file from CentOS client to CentOS server user, IP address, directory on client
[root@primary ~] # scp [email protected]:/home/ClientTestFile1.txt /root
♦ Copy file from CentOS server to MacOS host user, IP address, directory on MacOS
[root@primary ~] # scp /root/ServerTestFile2.txt [email protected]:/Users/xman/Desktop
♦ Copy file from MacOS host to CentOS server user, IP address, directory on MacOS
[root@primary ~] # scp [email protected]:/Users/xman/MacOSTestFile.txt /root
Set Hostname
Hostname is a label that is assigned to a device connected to a computer network and used to identify that
device. In this case:
primary is a hostname
vanndy is a domain name
edu is top level domain (TLD)
♣ /usr/bin/yum
♦ Shows the content of yum directory
[root@primary ~] # ll /usr/bin/yum
♣ /usr/bin/dnf
♦ Shows the content of dnf directory
[root@primary ~] # ll /usr/bin/dnf
♦ Check whether the configuration files of yum package link to dnf or not
[root@primary ~] # ll /etc/yum.conf
♦ In case you want to change to another version of installed module; EX: from postgresql 13 to 12
♦ Reset (remove) the current module
[root@primary ~] # dnf module reset -y postgresql
♣ Add line 8:
priority=10
♣ Add line 8:
priority=10
♦ In case if you want to install particular packages directly from EPEL repository, connect to the Internet
[root@primary ~] # dnf --enablerepo=epel -y install [package1 package2]
♦ In case if you want to install particular packages directly from EL repository, connect to the Internet
[root@primary ~] # dnf --enablerepo=elrepo -y install [package1 package2]
♦ Install remi-release package. Remi repository provides useful packages like latest PHP and so on. More
information about Remi repository: https://rpms.remirepo.net
[root@primary ~] # dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
♦ Find out what are the configuration files of Remi repository enabled
[root@primary ~] # grep 'enabled=1' /etc/yum.repos.d/remi-*
/etc/yum.repos.d/remi-modular.repo:enabled=1
/etc/yum.repos.d/remi-safe.repo:enabled=1
♦ In case if you want to install particular packages directly from Remi Modular repository, connect to the
Internet
[root@primary ~] # dnf --enablerepo= remi- modular -y install [package1 package2]
♦ In case if you want to install particular packages directly from Remi Safe repository, connect to the Internet
[root@primary ~] # dnf --enablerepo= remi-safe -y install [package1 package2]
[InstallMedia-AppStream]
name=CentOS Linux 8 - AppStream
metadata_expire=-1
gpgcheck=1
enabled=1
baseurl=file:///mnt/Linux/AppStream
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
♦ Test by installing a simple package without the Internet connection; EX: Nginx and tar
[root@primary ~] # yum -y install nginx tar
Note: from now on when we want to install any package, we do not need to connect to the Internet anymore, we
just connect the CentOS DVD ISO file to the VM CD ROM and mount the CD to the folder /mnt/Linux.
♦ Follow the instruction to install VMware Tools (just press enter). After finishing installation, restart the OS.
♦ Remove the directory /root/vmware-tools-distrib
[root@primary ~] # rm -rf /root/vmware-tools-distrib
♦ Test by editing any configuration file and make sure that VIM feature works
[root@primary ~] # vi /etc/yum.repos.d/CentOS-Local.repo
♦ Add users
[root@primary ~] # useradd redhat
[root@primary ~] # useradd ubuntu
[root@primary ~] # useradd debian
[root@primary ~] # useradd testing
♦ Switch from user “root” to normal user; EX: switch to user “ubuntu”
[root@primary ~] # su ubuntu
♦ Delete a user
[root@primary ~] # userdel -r testing
♦ View the home directory again and make sure that home directory of user “testing” is gone
[root@primary ~] # ll /home
♣ Line 7: uncomment
auth required pam_wheel.so use_uid
♦ Login with normal user; EX: user ubuntu. Try using “sudo” command, and make sure that it shows like this:
ubuntu is not in the sudoers file. This incident will be reported.
[ubuntu@primary ~] # sudo passwd
Disable IPV6
IPV6 should be disable because it is no use right now; more importantly, it makes server’s configuration more
complicated and may affect to server privacy.
♦ Restart the server then test with a command below; make sure there is no inet6
[root@primary ~] # ip addr show
♦ Restart the server and make sure that boot menu does not appear anymore
[root@primary ~] # init 6
Disable Firewall
Firewall should be configured on the gateway, so it is unnecessary to run it on the server. Moreover, Firewall
makes the server configuration more complicated since we need to set the rule on Firewall for every service.
♦ Restart the server and use command below to see all active services; make sure Firewall service not running
[root@primary ~] # systemctl -t service
♦ Use the command below to check the status of Firewall services; make sure it is inactive
[root@primary ~] # systemctl status firewalld
♦ Restart the server then check the status of SELinux again, and make sure it is disabled
♦ Enter your passphrase that you set when creating key pair
♦ Click Save private key; EX: Private Key.ppk
♦ Edit SSH configuration file
[root@primary ~] # vi /etc/ssh/sshd_config
♦ From now on, we cannot remote login to the server with SSH password authentication, we have to use the
private key file and the passphrase.
♦ Steps to remote login to the server with SSH private key:
♣ Open PuTTY and enter the server’s IP address
♣ In the Category left panel go to Connection => SSH => Auth
♣ Click Browse… and locate for the private key you just saved
♣ Enter your passphrase (not user root’s password)
♦ You can also remote login to the server via PuTTY Authentication Agent
♣ Open the Private Key.ppk on Windows Desktop
♣ Enter your passphrase
♣ Open PuTTY and enter the server’s IP address, then login directly without entering passphrase again
♦ From now on, we cannot remote login to the server with SSH password authentication, we have to use the
private key file and the passphrase.
♦ Steps to remote login to the server with SSH private key:
♣ On Mac, rename the private key file id_rsa to id_rsa.pem
♣ Open Terminal and enter command
xman@Xs-MacBook-Pro ~ % ssh -i /Users/xman/Desktop/id_rsa.pem [email protected]
♣ Accept and enter the passphrase of key pair (not user root’s password)
♣ To logout from remote server
[root@primary ~]# exit
♣ Add passphrase
xman@Xs-MacBook-Pro ~ % ssh-add /Users/xman/Desktop/id_rsa.pem
♣ Verify passphrase
xman@Xs-MacBook-Pro ~ % ssh-add -l
♣ After you stop remote to the server, you can kill SSH-Agent process
xman@Xs-MacBook-Pro ~ % eval $(ssh-agent -k)
♦ From now on, we cannot remote login to the server with SSH password authentication, we have to use the
private key file and the passphrase.
♦ Steps to remote login to the server with SSH private key:
♣ On Linux OS, rename the private key file id_rsa to id_rsa.pem
♣ Open Terminal and enter command
ssh -i /home/xman/Desktop/id_rsa.pem [email protected]
♣ Add passphrase
ssh-add /home/xman/Desktop/id_rsa.pem
♣ Verify passphrase
ssh-add -l
♣ After you stop remote to the server, you can kill SSH-Agent process
eval $(ssh-agent -k)
♦ In this case, my hostname is primary, and my domain name is vanndy.edu. You may need to change them.
♦ Install dnsmasq packages
[root@primary ~] # yum -y install dnsmasq
♦ Edit dnsmasq configuration file
[root@primary ~] # vi /etc/dnsmasq.conf
♣ Line 19: uncomment – never forward addresses in the non-routed address spaces
domain-needed
♣ Line 21: uncomment – query with each server strictly in the order in resolv.conf
bogus-priv
♣ Line 53: uncomment – query with each server strictly in the order in resolv.conf
strict-order
♣ Add to EoF:
192.168.11.10 primary.vanndy.edu Primary
♣ Line 157: uncomment and define range of IP address to lease and term of lease duration; EX: 15 days
dhcp-range=192.168.11.12,192.168.11.50,360h
♦ In this case, my hostname is primary, and my domain name is vanndy.edu. You may need to change them.
♦ Install bind and bind-utils packages
[root@primary ~] # yum -y install bind bind-utils
♣ Add to EoF: we do not use IPv6, so we set BIND to use only IPv4
OPTIONS="-4"
♦ Disconnect from the Internet and test DNS with commands below, make sure the ANSWER SECTION and
AUTHORITY SECTION are correct
[root@primary ~] # dig primary.vanndy.edu.
[root@primary ~] # dig www.vanndy.edu.
[root@primary ~] # dig ftp.vanndy.edu.
[root@primary ~] # nslookup primary.vanndy.edu
Note: for Mac OS, you have to disable Remote network card first, then login directly to the server before testing
the commands above. This is the problem of VMware Fusion.
♦ Disable the Remote network card and test the commands above
[root@primary ~] # ifdown ens192
Note: from now on, the configuration files of named is located in: /var/named/chroot/
♦ Check the leased IP address that DHCP Server provide to DHCP Clients in the files below
[root@primary ~]# ll /var/lib/dhcpd
[root@primary ~]# cat /var/lib/dhcpd/dhcpd.leases
Go to Windows client and configure VMnet1 network card to use DHCP service
♣ Line 3: comment
#pool 2.centos.pool.ntp.org iburst
♣ Add line 4
server 0.kh.pool.ntp.org
♣ Line 24: uncomment and change to 192.168.11.0/24. This adds the network range you allow to request
NTP time synchronization form your server
allow 192.168.11.0/24
♣ The option --now forces the service to start now without the option start
♦ For testing, connect to the Internet and use command below to synchronize the time
[root@primary ~]# chronyc sources
Go to Linux client and configure section 16
♦ Make a shared folder on the server to allow client to access as a file server
[root@primary ~] # mkdir /root/nfsServer
♦ Create some sample folders and files inside the nfsServer folder
♦ Create an export file to set permission for the shared folder
[root@primary ~] # vi /etc/exports
♦ Check if the mounting process is success or not, make sure all the sample folders and files inside the
nfsServer folder is mounted to 123 folder
[root@primary ~] # ll /root/123
Note: for Mac OS user, you have to disable Internet network card first, then login directly to the server before
testing the commands above. This is the problem of VMware Fusion.
♦ Disable the Internet network card and test the commands above
[root@primary ~] # ifdown ens192
replace: olcAccess
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=vanndy,dc=edu
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=Manager,dc=vanndy,dc=edu
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxx
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by dn="cn=Manager,dc=vanndy,dc=edu"
write by anonymous auth by self write by * none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=Manager,dc=vanndy,dc=edu" write by * read
dn: cn=Manager,dc=vanndy,dc=edu
objectClass: organizationalRole
cn: Manager
description: Directory Manager
dn: ou=People,dc=vanndy,dc=edu
objectClass: organizationalUnit
ou: People
dn: ou=Group,dc=vanndy,dc=edu
objectClass: organizationalUnit
ou: Group
Add Local Users and Groups of the Server to Become LDAP Users
This section shows how to add local users into LDAP server automatically.
SUFFIX='dc=vanndy,dc=edu'
LDIF='ldapuser.ldif'
do
UID_NUM=$(echo "$MEMBER_UID" | cut -d':' -f2)
[ $UID_NUM -ge 1000 -a $UID_NUM -le 9999 ] && echo "memberUid: $(echo "$MEMBER_UID" | cut -d':' -f1)" >> $LDIF
done
echo >> $LDIF
done
)
Add LDAP User Accounts into OpenLDAP Server (Not the Local Users of Server)
This section shows how to add users to LDAP server manually. EX: we want to add a user named Linux Cent.
♦ Enter the LDAP admin’s password and copy the {SSHA}xxxxx to a text file
Note: cn is common name and sn is surname.
♦ Edit LDIF file to store user’s configuration
[root@primary ~] # vi ldapuser.ldif
dn: uid=cent,ou=People,dc=vanndy,dc=edu
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: Cent
sn: Linux
userPassword: {SSHA}xxxxx
loginShell: /bin/bash
uidNumber: 1000
gidNumber: 1000
homeDirectory: /home/cent
dn: cn=cent,ou=Group,dc=vanndy,dc=edu
objectClass: posixGroup
cn: Cent
gidNumber: 1000
memberUid: cent
♦ Copy the generated key to the certificate folder of LDAP service. Enter the commands below line by line.
[root@primary ~] # cp /etc/pki/tls/certs/server.key \
/etc/pki/tls/certs/server.crt \
/etc/pki/tls/certs/ca-bundle.crt \
/etc/openldap/certs/
♦ Change the ownership of the certificate for LDAP service. Enter the commands below line by line.
[root@primary ~] # chown ldap. /etc/openldap/certs/server.key \
/etc/openldap/certs/server.crt \
/etc/openldap/certs/ca-bundle.crt
♦ Copy the file /etc/pki/tls/cert.pem from server to the Linux client /etc/openldap/cacerts/
[root@primary ~] # scp /etc/pki/tls/cert.pem [email protected]:/etc/openldap/cacerts/
♣ Add to EoF
ServerTokens Prod
KeepAlive On
</div>
</body>
</html>
♣ Line 902: uncomment (delete sign ; from the beginning of the line) and add Asia/Phnom_Penh
date.timezone = "Asia/Phnom_Penh"
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
<?php
?>
</div>
</body>
</html>
♣ Add line 12
Require ip 192.168.11.0/24
♦ Log out from user ubuntu, and remote login to user root
♦ Edit HTML index file of user ubuntu
[root@primary ~] # vi /home/ubuntu/public_html/index.html
<html>
<body>
</body>
</html>
<body>
</div>
</body>
</html>
♣ Add to EoF:
<Directory /var/www/html/auth-pam>
SSLRequireSSL
AuthType Basic
AuthName "PAM Authentication"
AuthBasicProvider external
AuthExternal pwauth
require valid-user
</Directory>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
This web page can be accessed only by OS local user authentication
</div>
</body>
</html>
</div>
</body>
</html>
Configure WebDAV
Web Distributed Authoring and Versioning (WebDAV) is an extension of the HTTP that allows clients to
perform remote Web content authoring operations. The WebDAV protocol provides a framework for users to
create, change and move documents on a server, typically a web server or web share. The most important
features of the WebDAV protocol include the maintenance of properties about an author or modification date,
namespace management, collections, and overwrite protection.
Note: you have to generate the report every time you want to get the latest update.
♦ From Linux or Windows client, access to https://www.vanndy.edu/awstats/awstats.pl
♣ Line 6: character-set-server=utf8
character-set-server=utf8
♣ Add to EoF
local_root=public_html
use_localtime=YES
seccomp_sandbox=NO
♣ Add to EoF
rsa_cert_file=/etc/pki/tls/certs/vsftpd.pem
ssl_enable=YES
force_local_data_ssl=YES
force_local_logins_ssl=YES
♣ Add to EoF
message_size_limit = 10485760
mailbox_size_limit = 1073741824
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject
Note: for Windows and Linux hosts (VMware Workstation), you have to disconnect from the Internet first before
running the commands below. For Mac OS host (VMware Fusion), you have to disable Remote network card
first, then login directly to the server before running commands below. After that you can enable Remote network
card. This is a problem of VMware Fusion.
♦ Disable the Remote network card and test the commands above
[root@primary ~] # ifdown ifcfg-ens192
Note: if the server repose as above, then it is OK, but if not, we need to check DNS server, SMTP server,
POP/IMAP server again.
none, login, plain, cram-md5, or digest-md5 [none]: login
SMTP connections? [y/N]: N
Command >> R
Command >> 4
Command >> 7
Hide SM attributions (y/n) [n]: y
Command >> R
Command >> 8
Command >> 7
Command >> 8
Command >> 15
Command >> Q
Save? [Y/n]: y
♦ Add to EoF
centos = centospass
redhat = redhatpass
ubuntu = ubuntupass
debian = debianpass
♦ Edit authentication method of SVN server
[root@primary ~]# vi /var/svn/repos/project/conf/authz
♣ Add line 17
dos charset = CP932
♣ Add line 18
hosts allow = 127. 192.168.11.
♣ Add to EoF:
[Security]
path = /home/security
writable = yes
create mode = 0770
directory mode = 0770
guest ok = no
valid users = @security
♦ Add any local user to become a user of Samba; EX: user debian
[root@primary ~]# smbpasswd -a debian