{"id":11733,"date":"2019-03-16T03:47:39","date_gmt":"2019-03-16T03:47:39","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11733"},"modified":"2019-03-16T03:47:39","modified_gmt":"2019-03-16T03:47:39","slug":"initial-ubuntu-server-setup-for-beginners","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/16\/initial-ubuntu-server-setup-for-beginners\/","title":{"rendered":"Initial Ubuntu Server Setup for Beginners"},"content":{"rendered":"<p>This tutorial will guide you on the first basic steps you need to configure on a new installed Ubuntu server in order to increase security and reliability for your server.<\/p>\n<p>The configurations explained in this topic are almost the same for all Ubuntu server systems, regarding of the underlying OS platform, whether Ubuntu is installed on a bare-metal server, in a private virtual machine or a virtual machine spinned-out in a VPS public cloud.<\/p>\n<h4>Requirements<\/h4>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/installation-of-ubuntu-16-04-server-edition\/\" target=\"_blank\" rel=\"noopener\">Ubuntu Server Edition installation<\/a><\/li>\n<\/ol>\n<h3>Update and Upgrade Ubuntu System<\/h3>\n<p>The first step you need to take care of in case of fresh installation of Ubuntu server or a new deployed Ubuntu VPS is to make sure the system and all system components, such as the kernel, the package manager and all other installed packages are up-to-date with the latest released versions and security patches.<\/p>\n<p>To update Ubuntu server, to log in to server\u2019s console with an account with root privileges or directly as root and run the below commands in order to perform the update and upgrade process.<\/p>\n<pre>$ sudo apt update \r\n<\/pre>\n<div id=\"attachment_27650\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Update-Ubuntu-Server.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27650\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Update-Ubuntu-Server.png\" sizes=\"auto, (max-width: 853px) 100vw, 853px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Update-Ubuntu-Server.png 853w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Update-Ubuntu-Server-768x172.png 768w\" alt=\"Update Ubuntu Server\" width=\"853\" height=\"191\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Update Ubuntu Server<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<p>After running the update command, you will see the number of available packages for upgrading process and the command used for listing the packages upgrades.<\/p>\n<pre>$ sudo apt list --upgradable\r\n<\/pre>\n<div id=\"attachment_27651\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Upgrade-Ubuntu-Server.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27651\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Upgrade-Ubuntu-Server.png\" alt=\"List Upgrade Ubuntu Packages\" width=\"755\" height=\"217\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">List Upgrade Ubuntu Packages<\/p>\n<\/div>\n<p>After you\u2019ve consulted the list of packages available for upgrading, issue the below command to start system upgrade process.<\/p>\n<pre>$ sudo apt upgrade\r\n<\/pre>\n<div id=\"attachment_27652\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Upgrade-Ubuntu-Server-Packages.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27652\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Upgrade-Ubuntu-Server-Packages.png\" alt=\"Upgrade Ubuntu Server Packages\" width=\"747\" height=\"548\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Upgrade Ubuntu Server Packages<\/p>\n<\/div>\n<p>In order to remove all locally downloaded deb packages and all other\u00a0<a href=\"https:\/\/www.tecmint.com\/useful-basic-commands-of-apt-get-and-apt-cache-for-package-management\/\" target=\"_blank\" rel=\"noopener\">apt-get caches<\/a>, execute the below command.<\/p>\n<pre>$ sudo apt autoremove\r\n$ sudo apt clean\r\n<\/pre>\n<div id=\"attachment_27653\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Autoremove-APT-Packages-and-Cache.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27653\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Autoremove-APT-Packages-and-Cache.png\" alt=\"Autoremove APT Packages and Cache\" width=\"713\" height=\"277\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Autoremove APT Packages and Cache<\/p>\n<\/div>\n<h3>Create New Account in Ubuntu<\/h3>\n<p>By default, as a security measure, the root account is completely disabled in Ubuntu. In order to create a new account on the system, log in to the system with the account user with root privileges and create a new account with the below command.<\/p>\n<p>This new account will be granted with root powers privileges via\u00a0<a href=\"https:\/\/www.tecmint.com\/sudoers-configurations-for-setting-sudo-in-linux\/\" target=\"_blank\" rel=\"noopener\">sudo command<\/a>\u00a0and will be used to perform administrative tasks in the system. Make sure you setup a strong password to protect this account. Follow the\u00a0<strong>adduser<\/strong>\u00a0prompt to setup the user details and password.<\/p>\n<pre>$ sudo adduser ubuntu_user\r\n<\/pre>\n<div id=\"attachment_27654\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Create-User-in-Ubuntu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27654\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Create-User-in-Ubuntu.png\" alt=\"Create User in Ubuntu\" width=\"726\" height=\"348\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Create User in Ubuntu<\/p>\n<\/div>\n<p>If this account will be assigned to another system admin, you can force the user to change its password at the first log in attempt by issuing the following command.<\/p>\n<pre>$ sudo chage -d0 ubuntu_user\r\n<\/pre>\n<p>For now, the new added user cannot perform administrative tasks via sudo utility. To grant this new user account with administrative privileges you should add the user to \u201c<strong>sudo<\/strong>\u201d system group by issuing the below command.<\/p>\n<pre>$ sudo usermod -a -G sudo ubuntu_user\r\n<\/pre>\n<p>By default, all users belonging to the \u201c<strong>sudo<\/strong>\u201d group are allowed to execute commands with root privileges via\u00a0<a href=\"https:\/\/www.tecmint.com\/run-sudo-command-without-password-linux\/\" target=\"_blank\" rel=\"noopener\">sudo utility<\/a>. Sudo command must be used before writing the command needed for execution, as shown in the below example.<\/p>\n<pre>$ sudo apt install package_name\r\n<\/pre>\n<p>Test if the new user has the root privileges granted, by logging in to the system and run the\u00a0<strong>apt update<\/strong>command prefixed with sudo.<\/p>\n<pre>$ su - ubuntu_user\r\n$ sudo apt update\r\n<\/pre>\n<div id=\"attachment_27655\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Verify-New-User.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27655\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Verify-New-User.png\" alt=\"Verify New User\" width=\"623\" height=\"401\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Verify New User<\/p>\n<\/div>\n<h3>Configure System Hostname in Ubuntu<\/h3>\n<p>Usually, the machine hostname is set-up during the system installation process or when the VPS is created in the cloud. However, you should change the name of your machine in order to better reflect the destination of your server or to better describe its final purpose.<\/p>\n<p>In a large company, machines are named after complex naming schemes in order to easily identify the machine in datacenter\u2019s racks. For instance, if your Ubuntu machine will operate a mail server, the name of the machine should reflect this fact and you can setup machine hostname as\u00a0<strong>mx01.mydomain.lan<\/strong>, for example.<\/p>\n<p>To show details about your machine hostname run the following command.<\/p>\n<pre>$ hostnamectl\r\n<\/pre>\n<p>In order to change the name of your machine, issue\u00a0<strong>hostnamectl command<\/strong>\u00a0with the new name you will configure for your machine, as illustrated in the below excerpt.<\/p>\n<pre>$ sudo hostnamectl set-hostname tecmint\r\n<\/pre>\n<p>Verify the new name of your system with one of the below commands.<\/p>\n<pre>$ hostname\r\n$ hostname -s\r\n$ cat \/etc\/hostname \r\n<\/pre>\n<div id=\"attachment_27656\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Set-Hostname-in-Ubuntu-Server.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27656\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Set-Hostname-in-Ubuntu-Server.png\" alt=\"Set Hostname in Ubuntu Server\" width=\"594\" height=\"341\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Set Hostname in Ubuntu Server<\/p>\n<\/div>\n<h3>Setup SSH with Public Key Authentication in Ubuntu<\/h3>\n<p>To increase system security degree of an Ubuntu server, you should set-up SSH public key authentication for an local account. In order to generate SSH Key Pair, the public and private key, with a specifying a key length, such as 2048 bits, execute the following command at your server console.<\/p>\n<p>Make sure you\u2019re logged in to the system with the user you\u2019re setting up the SSH key.<\/p>\n<pre>$ su - ubuntu_user\r\n$ ssh-keygen -t RSA -b 2048\r\n<\/pre>\n<div id=\"attachment_27657\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Setup-SSH-Keys-in-Ubuntu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27657\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Setup-SSH-Keys-in-Ubuntu.png\" sizes=\"auto, (max-width: 780px) 100vw, 780px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Setup-SSH-Keys-in-Ubuntu.png 780w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Setup-SSH-Keys-in-Ubuntu-768x473.png 768w\" alt=\"Setup SSH Keys in Ubuntu\" width=\"780\" height=\"480\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Setup SSH Keys in Ubuntu<\/p>\n<\/div>\n<p>While the key is generated, you will be prompted to add\u00a0<strong>passphrase<\/strong>\u00a0in order to secure the key. You can enter a strong passphrase or choose to leave the passphrase blank if you want to automate tasks via SSH server.<\/p>\n<p>After the SSH key has been generated, you can copy the public key to a remote server by executing the below command. To install the public key to the remote SSH server you will need a remote user account with the proper permissions and credentials to log in to remote server.<\/p>\n<pre>$ ssh-copy-id remote_user@remote_server\r\n<\/pre>\n<div id=\"attachment_27658\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Copy-SSH-Key-to-Remote-Server.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27658\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Copy-SSH-Key-to-Remote-Server.png\" alt=\"Copy SSH Key to Remote Server\" width=\"681\" height=\"289\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Copy SSH Key to Remote Server<\/p>\n<\/div>\n<p>You should be able to automatically log in via SSH to the remote server using the public key authentication method. You won\u2019t need to add the remote user password while using SSH public key authentication.<\/p>\n<p>After you\u2019ve logged in to the remote server, you can start to execute commands, such as\u00a0<strong>w command<\/strong>\u00a0to list ssh remote logged in users, as shown in the below screenshot.<\/p>\n<p>Type exit in the console to close the remote SSH session.<\/p>\n<pre>$ ssh remote_user@remote_server\r\n$ w\r\n$ exit\r\n<\/pre>\n<div id=\"attachment_27659\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Verify-SSH-Passwordless-Login.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27659\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Verify-SSH-Passwordless-Login.png\" sizes=\"auto, (max-width: 796px) 100vw, 796px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Verify-SSH-Passwordless-Login.png 796w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Verify-SSH-Passwordless-Login-768x333.png 768w\" alt=\"Verify SSH Passwordless Login\" width=\"796\" height=\"345\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Verify SSH Passwordless Login<\/p>\n<\/div>\n<p>To see the content of your public SSH key in order to manually install the key to a remote SSH server, issue the following command.<\/p>\n<pre>$ cat ~\/.ssh\/id_rsa.pub\r\n<\/pre>\n<div id=\"attachment_27660\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/View-SSH-Key.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27660\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/View-SSH-Key.png\" alt=\"View SSH Key\" width=\"621\" height=\"124\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">View SSH Key<\/p>\n<\/div>\n<h3>Secure SSH Server in Ubuntu<\/h3>\n<p>In order to secure the SSH daemon you should change the default SSH port number from\u00a0<strong>22<\/strong>\u00a0to a random port, higher than\u00a0<strong>1024<\/strong>, and disallow remote SSH access to the root account via password or key, by opening SSH server main configuration file and make the following changes.<\/p>\n<pre>$ sudo vi \/etc\/ssh\/sshd_config\r\n<\/pre>\n<p>First, search the commented line\u00a0<strong>#Port22<\/strong>\u00a0and add a new line underneath (replace the listening port number accordingly):<\/p>\n<pre>Port 2345\r\n<\/pre>\n<p>Don\u2019t close the file, scroll down and search for the line\u00a0<strong>#PermitRootLogin yes<\/strong>, uncomment the line by removing the\u00a0<strong>#<\/strong>\u00a0sign (hashtag) from the beginning of the line and modify the line to look like shown in the below excerpt.<\/p>\n<pre>PermitRootLogin no\r\n<\/pre>\n<div id=\"attachment_27661\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Secure-SSH-Service.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27661\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Secure-SSH-Service.png\" sizes=\"auto, (max-width: 849px) 100vw, 849px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Secure-SSH-Service.png 849w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Secure-SSH-Service-768x449.png 768w\" alt=\"Secure SSH Service\" width=\"849\" height=\"496\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Secure SSH Service<\/p>\n<\/div>\n<p>Afterwards, restart the SSH server to apply the new settings and test the configuration by trying to log in from a remote machine to this server with the root account via the new port number. The access to root account via SSH should be restricted.<\/p>\n<pre>$ sudo systemctl restart sshd\r\n<\/pre>\n<p>Also, run\u00a0<a href=\"https:\/\/www.tecmint.com\/20-netstat-commands-for-linux-network-management\/\" target=\"_blank\" rel=\"noopener\">netstat<\/a>\u00a0or\u00a0<strong>ss command<\/strong>\u00a0and filter the output via\u00a0<a href=\"https:\/\/www.tecmint.com\/12-practical-examples-of-linux-grep-command\/\" target=\"_blank\" rel=\"noopener\">grep<\/a>\u00a0in order to show the new listening port number for SSH server.<\/p>\n<pre>$ sudo ss -tlpn| grep ssh\r\n$ sudo netstat -tlpn| grep ssh\r\n<\/pre>\n<div id=\"attachment_27662\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Verify-SSH-Port.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27662\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Verify-SSH-Port.png\" alt=\"Verify SSH Port\" width=\"612\" height=\"149\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Verify SSH Port<\/p>\n<\/div>\n<p>There are situations where you might want to automatically\u00a0<a href=\"https:\/\/www.tecmint.com\/tmout-auto-logout-linux-shell-idle-sessions\/\" target=\"_blank\" rel=\"noopener\">disconnect all remote SSH connections<\/a>\u00a0established into your server after a period of inactivity.<\/p>\n<p>In order to enable this feature, execute the below command, which adds the\u00a0<strong>TMOUT<\/strong>\u00a0bash variable to your account\u00a0<strong>.bashrc<\/strong>\u00a0hidden file and forces every SSH connection made with the name of the user to be disconnected or dropped-out after 5 minutes of inactivity.<\/p>\n<pre>$ echo 'TMOUT=300' &gt;&gt; .bashrc\r\n<\/pre>\n<p>Run\u00a0<a href=\"https:\/\/www.tecmint.com\/view-contents-of-file-in-linux\/\" target=\"_blank\" rel=\"noopener\">tail command<\/a>\u00a0to check if the variable has been correctly added at the end of\u00a0<strong>.bashrc<\/strong>\u00a0file. All subsequent SSH connections will be automatically closed after 5 minutes of inactivity from now on.<\/p>\n<pre>$ tail .bashrc\r\n<\/pre>\n<p>In the below screenshot, the remote SSH session from drupal machine to Ubuntu server via ubuntu_user account has been timed out and auto-logout after 5 minutes.<\/p>\n<div id=\"attachment_27627\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Auto-Disconnect-SSH-Sessions.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27627\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Auto-Disconnect-SSH-Sessions.png\" alt=\"Auto Disconnect SSH Sessions\" width=\"555\" height=\"109\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Auto Disconnect SSH Sessions<\/p>\n<\/div>\n<h3>Configure Ubuntu Firewall UFW<\/h3>\n<p>Every server needs a well configured firewall in order to secure the system at network level. Ubuntu server uses\u00a0<strong>UFW<\/strong>\u00a0application to manage the iptables rules on the server.<\/p>\n<p>Check the status of UFW firewall application in Ubuntu by issuing the below commands.<\/p>\n<pre>$ sudo systemctl status ufw\r\n$ sudo ufw status\r\n<\/pre>\n<div id=\"attachment_27663\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Check-UFW-Firewall-Status.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27663\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Check-UFW-Firewall-Status.png\" alt=\"Check UFW Firewall Status\" width=\"562\" height=\"244\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check UFW Firewall Status<\/p>\n<\/div>\n<p>Usually, the UFW firewall daemon is up and running in Ubuntu server, but the rules are not applied by default. Before enabling UFW firewall policy in you system, first you should add a new rule to allow SSH traffic to pass through firewall via the changed SSH port. The rule can be added by executing the below command.<\/p>\n<pre>$ sudo ufw allow 2345\/tcp\r\n<\/pre>\n<p>After you\u2019ve allowed SSH traffic, you can enable and check UFW firewall application with the following commands.<\/p>\n<pre>$ sudo ufw enable\r\n$ sudo ufw status\r\n<\/pre>\n<div id=\"attachment_27664\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Open-SSH-Port-and-Verify.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27664\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Open-SSH-Port-and-Verify.png\" alt=\"Open SSH Port and Verify\" width=\"590\" height=\"294\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Open SSH Port and Verify<\/p>\n<\/div>\n<p>To add new firewall rules for other network services subsequently installed on your server, such as HTTP server, a mail server or other network services, use the below firewall commands examples as guide.<\/p>\n<pre>$ sudo ufw allow http  #allow http traffic\r\n$ sudo ufw allow proto tcp from any to any port 25,443  # allow https and smtp traffic\r\n<\/pre>\n<p>To list all firewall rules run the below command.<\/p>\n<pre>$ sudo ufw status verbose\r\n<\/pre>\n<div id=\"attachment_27665\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Check-UFW-Firewall-Rules.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27665\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Check-UFW-Firewall-Rules.png\" alt=\"Check UFW Firewall Rules\" width=\"673\" height=\"424\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check UFW Firewall Rules<\/p>\n<\/div>\n<h3>Set Ubuntu Server Time<\/h3>\n<p>To control or query Ubuntu server clock and other related time settings, execute\u00a0<a href=\"https:\/\/www.tecmint.com\/set-time-timezone-and-synchronize-time-using-timedatectl-command\/\" target=\"_blank\" rel=\"noopener\">timedatectl command<\/a>\u00a0with no argument.<\/p>\n<p>In order to change your server\u2019s time zone settings, first execute\u00a0<strong>timedatectl command<\/strong>\u00a0with list-timezones argument to list all available time zones and, then, set the time zone of your system as shown in the below excerpt.<\/p>\n<pre>$ sudo timedatectl \r\n$ sudo timedatectl list-timezones \r\n$ sudo timedatectl set-timezone Europe\/Vienna\r\n<\/pre>\n<div id=\"attachment_27666\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Set-Ubuntu-Timezone.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27666\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Set-Ubuntu-Timezone.png\" alt=\"Set Ubuntu Timezone\" width=\"732\" height=\"196\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Set Ubuntu Timezone<\/p>\n<\/div>\n<p>The new\u00a0<strong>systemd-timesyncd<\/strong>\u00a0systemd daemon client can be utilized in Ubuntu in order to provide an accurate time for your server across network and synchronize time with an upper time peer server.<\/p>\n<p>To apply this new feature of Systemd, modify\u00a0<strong>systemd-timesyncd<\/strong>\u00a0daemon configuration file and add the closest geographically NTP servers to NTP statement line, as shown in the below file excerpt:<\/p>\n<pre>$ sudo nano \/etc\/systemd\/timesyncd.conf\r\n<\/pre>\n<p>Add following configuration to\u00a0<strong>timesyncd.conf<\/strong>\u00a0file:<\/p>\n<pre>[Time]\r\nNTP=0.pool.ntp.org 1.pool.ntp.org\r\nFallbackNTP=ntp.ubuntu.com\r\n<\/pre>\n<div id=\"attachment_27667\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/NTP-Configuration.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27667\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/NTP-Configuration.png\" alt=\"NTP Time Configuration\" width=\"556\" height=\"331\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">NTP Time Configuration<\/p>\n<\/div>\n<p>To add your nearest geographically NTP servers, consult the NTP pool project server list at the following address:\u00a0<a href=\"http:\/\/www.pool.ntp.org\/en\/\" target=\"_blank\" rel=\"noopener nofollow\">http:\/\/www.pool.ntp.org\/en\/<\/a><\/p>\n<p>Afterwards, restart the Systemd timesync daemon to reflect changes and check daemon status by running the below commands. After restart, the daemon will start to sync time with the new ntp server peer.<\/p>\n<pre>$ sudo systemctl restart systemd-timesyncd.service \r\n$ sudo systemctl status systemd-timesyncd.service\r\n<\/pre>\n<div id=\"attachment_27668\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Start-TimeSyncd-Service.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27668\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Start-TimeSyncd-Service.png\" sizes=\"auto, (max-width: 819px) 100vw, 819px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Start-TimeSyncd-Service.png 819w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Start-TimeSyncd-Service-768x394.png 768w\" alt=\"Start TimeSyncd Service\" width=\"819\" height=\"420\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Start TimeSyncd Service<\/p>\n<\/div>\n<h3>Disable and Remove Unneeded Services in Ubuntu<\/h3>\n<p>In order to get a list of all TCP and UDP network services up-and-running by default in your Ubuntu server, execute the\u00a0<strong>ss<\/strong>\u00a0or\u00a0<a href=\"https:\/\/www.tecmint.com\/20-netstat-commands-for-linux-network-management\/\" target=\"_blank\" rel=\"noopener\">netstat command<\/a>.<\/p>\n<pre>$ sudo netstat -tulpn\r\nOR\r\n$ sudo ss -tulpn\r\n<\/pre>\n<div id=\"attachment_27669\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/List-All-Running-Services.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27669\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/List-All-Running-Services.png\" alt=\"List All Running Services\" width=\"661\" height=\"298\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">List All Running Services<\/p>\n<\/div>\n<p>Staring with\u00a0<strong>Ubuntu 16.10<\/strong>\u00a0release, the default DNS resolver is now controlled by\u00a0<strong>systemd-resolved<\/strong>\u00a0service, as revealed by the output of\u00a0<strong>netstat<\/strong>\u00a0or\u00a0<strong>ss commands<\/strong>.<\/p>\n<p>You should also check the\u00a0<strong>systemd-resolved<\/strong>\u00a0service status by running the following command.<\/p>\n<pre>$ sudo systemctl status systemd-resolved.service\r\n<\/pre>\n<div id=\"attachment_27670\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Check-Systemd-resolved-Status.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27670\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Check-Systemd-resolved-Status.png\" sizes=\"auto, (max-width: 795px) 100vw, 795px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Check-Systemd-resolved-Status.png 795w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Check-Systemd-resolved-Status-768x317.png 768w\" alt=\"Check Systemd Resolved Status\" width=\"795\" height=\"328\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check Systemd Resolved Status<\/p>\n<\/div>\n<p>The\u00a0<strong>systemd-resolved<\/strong>\u00a0service binds on all enabled network interfaces and listens on ports\u00a0<strong>53<\/strong>\u00a0and\u00a0<strong>5355 TCP<\/strong>and\u00a0<strong>UDP<\/strong>.<\/p>\n<p>Running\u00a0<strong>system-resolved<\/strong>\u00a0caching DNS daemon on a production server can be dangerous due to the numerous number of DDOS attacks performed by malicious hackers against unsecured DNS servers.<\/p>\n<p>In order to stop and disable this service, execute the following commands.<\/p>\n<pre>$ sudo systemctl stop systemd-resolved\r\n$ sudo systemctl disable systemd-resolved\r\n<\/pre>\n<div id=\"attachment_27671\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Disable-Systemd-Resolved.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27671\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Disable-Systemd-Resolved.png\" alt=\"Disable Systemd Resolved Service\" width=\"695\" height=\"84\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Disable Systemd Resolved Service<\/p>\n<\/div>\n<p>Verify if the service has been stopped and disabled by issuing\u00a0<strong>ss<\/strong>\u00a0or\u00a0<strong>netstat command<\/strong>. The systemd-resolved listening ports, 53 and 5355 TCP and UDP, should not be listed in netstat or ss command output, as illustrated in the below.<\/p>\n<p>You should also reboot the machine in order to completely disable all systemd-resolved daemon services and restore the default\u00a0<strong>\/etc\/resolv.conf<\/strong>\u00a0file.<\/p>\n<pre>$ sudo ss -tulpn\r\n$ sudo netstat -tulpn\r\n$ sudo systemctl reboot\r\n<\/pre>\n<div id=\"attachment_27672\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Verify-All-Running-Services.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27672\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Verify-All-Running-Services.png\" alt=\"Verify All Running Services\" width=\"671\" height=\"229\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Verify All Running Services<\/p>\n<\/div>\n<p>Although, you\u2019ve disabled some unwanted networking services to run in your server, there are also other services installed and running in your system, such as\u00a0<strong>lxc<\/strong>\u00a0process and\u00a0<strong>snapd<\/strong>\u00a0service. These services can be easily detected via\u00a0<a href=\"https:\/\/www.tecmint.com\/ps-command-examples-for-linux-process-monitoring\/\" target=\"_blank\" rel=\"noopener\">ps<\/a>,\u00a0<a href=\"https:\/\/www.tecmint.com\/12-top-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">top<\/a>\u00a0or\u00a0<strong>pstree<\/strong>\u00a0commands.<\/p>\n<pre>$ sudo ps aux\r\n$ sudo top\r\n$ sudo pstree\r\n<\/pre>\n<div id=\"attachment_27673\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/List-Running-Services-in-Tree-Format.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27673\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/List-Running-Services-in-Tree-Format.png\" alt=\"List Running Services in Tree Format\" width=\"578\" height=\"501\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">List Running Services in Tree Format<\/p>\n<\/div>\n<p>In case you\u2019re not going to use LXC container virtualization in your server or start installing software packaged via Snap package manager, you should completely disable and remove these services, by issuing the below commands.<\/p>\n<pre>$ sudo apt autoremove --purge lxc-common lxcfs\r\n$ sudo apt autoremove --purge snapd\r\n<\/pre>\n<p>That\u2019s all! Now, Ubuntu server is now prepared for installing additional software needed for custom network services or applications, such as installing and configuring a web server, a database server, a file share service or other specific applications.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/initial-ubuntu-server-setup-guide\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will guide you on the first basic steps you need to configure on a new installed Ubuntu server in order to increase security and reliability for your server. The configurations explained in this topic are almost the same for all Ubuntu server systems, regarding of the underlying OS platform, whether Ubuntu is installed &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/16\/initial-ubuntu-server-setup-for-beginners\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Initial Ubuntu Server Setup for Beginners&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11733","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11733"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11733\/revisions"}],"predecessor-version":[{"id":11734,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11733\/revisions\/11734"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}