This guide includes the following steps: Let’s begin with the initial server setup on the Debian Linux system.
1. Upgrade Debian
After login into the Debian server, the first task is to upgrade the current packages of the Debian system. Because It may be the server is built with the old image file. The Debian team keeps working to enhance server security and provide updated packages regularly. First, update the Apt cache on your system. Then, run the upgrade command to actually upgrade packages. It’s also a good choice to run the dist-upgrade for a newly installed system. Press ‘Y’ for any confirmation prompted to complete the packages installation.
Also, execute the following command to remove packages no longer required. This is also helpful to remove files of the old kernel versions.
2. Create A Sudo User
Some of the hosting providers like DigitalOcean launches instances with root account only. This is not a good practice to keep using a production instance using the superuser account. We strongly recommend creating a new user with Sudo privileges and use that to accessing your Debian instance. Assuming you are already logged in a root account. Run the following command to create a new User on Debian:
The newly created account is a regular user. You will require the administrative privileges to perform multiple tasks. Grant the administrative privileges to this user by adding them in sudo group. To add user to sudo group, type: Now, you can switch to a newly created account for further instructions.
3. Configure System’s Hostname
A hostname of a system is the name of the instance used as an identity for computer networks. It helps users and network machine to easily recognize a machine within a network in a human-readable format. Its an good practice to set a proper hostname for your instance. In the system terminal type hostnamectl and hit enter: This will give you details about system details including hostname. Even you can type hostname command to view systems hostname. Next, change the system hostname to Once you updated the Systems’ hostname, you need to change to a new shell to activate in the current session. After changing the current shell, the shell prompt will be changed to a new hostname.
4. Securing SSH
SSH (Secure Shell) is the protocol used to connect remote servers. We recommended configuring the OpenSSH server to listen on a non-standard port. Which provides you another layer of security from hackers. To change the default port and disable root login, edit OpenSSH configuration file /etc/ssh/sshd_config and do the following changes.
Change Default Port – It will be good to change default ssh port as default ports are always on attackers. Port 2232 Disable Root SSH Login – Also you would like to disable root login via ssh. PermitRootLogin no
Save the configuration file and restart the OpenSSH service to apply changes.
5. Configuring Firewall (FirewallD)
The Default Debian server edition does not have a firewall installed on it. You can simply run the following command to install required packages from default repositories. On successful installation, firewall service will to auto started and enabled on your system. The default firewall allows SSH to the remote users. But if the SSH port is changed, you can add a rule to allow SSH access on another port. You can directly provide a service name like “http” or “https” to allow. The firewalld reads /etc/services file to determine the corresponding port of the service. After making any changes to your firewall, make sure to reload changes using the following command. To view, all the allowed ports and services use the following command. Output:
Conclusion
In this guide, we have gone through the initial server setup of a Debian Linux system. Once you successfully finished all the initial server setup configurations, your system is ready to use.