{"id":8025,"date":"2025-03-19T09:52:00","date_gmt":"2025-03-19T09:52:00","guid":{"rendered":"https:\/\/cloudvpshosts.com\/kb\/?p=8025"},"modified":"2026-11-21T18:39:50","modified_gmt":"2026-11-21T18:39:50","slug":"initial-server-setup-with-ubuntu","status":"publish","type":"post","link":"https:\/\/cloudvpshosts.com\/kb\/initial-server-setup-with-ubuntu\/","title":{"rendered":"Initial Server Setup with Ubuntu 24.04 and 22.04"},"content":{"rendered":"<p>Initial server setup on Ubuntu means doing a handful of security and housekeeping steps before you install anything else: update the system, create a regular user with sudo rights, log in with an SSH key instead of a password, turn off root login over SSH, and enable the UFW firewall. On a new Cloud VPS Hosts server this takes about fifteen minutes.<\/p>\n<p>This guide covers Ubuntu 24.04 LTS and Ubuntu 22.04 LTS. Run the commands in order on a fresh server. The examples use <code>203.0.113.10<\/code> as the server IP and <code>deploy<\/code> as the new username, so replace both with your own.<\/p>\n<h2>Why should you not work as root?<\/h2>\n<p>The root account can change anything on the server without asking, so a single typo or a stolen root password can take the whole machine down. A regular user with sudo rights has to confirm admin actions, every admin command is logged, and attackers who scan the internet for root logins find nothing to guess.<\/p>\n<h2>Step 1: Log in and update the system<\/h2>\n<p>Use the IP address and root password (or key) from your welcome email:<\/p>\n<pre><code>ssh root@203.0.113.10<\/code><\/pre>\n<p>Bring every package up to date before you change anything else:<\/p>\n<pre><code>apt update && apt upgrade -y<\/code><\/pre>\n<p>If the upgrade installed a new kernel, reboot with <code>reboot<\/code> and log in again.<\/p>\n<h2>Step 2: Create a user with sudo rights<\/h2>\n<pre><code>adduser deploy\r\nusermod -aG sudo deploy<\/code><\/pre>\n<p><code>adduser<\/code> asks for a password and optional details. Use a strong password, because sudo asks for it. The second command adds the user to the <code>sudo<\/code> group so it can run admin commands.<\/p>\n<h2>Step 3: Set up SSH key login for the new user<\/h2>\n<p>SSH keys are far harder to crack than passwords. If you do not have a key yet, create one on your own computer first with our guide to <a href=\"https:\/\/cloudvpshosts.com\/kb\/setting-up-an-ssh-key\/\">setting up an SSH key<\/a>. Then, from your computer, copy the public key to the server:<\/p>\n<pre><code>ssh-copy-id deploy@203.0.113.10<\/code><\/pre>\n<p>If root on the server already uses your key, you can copy it to the new user from the server instead:<\/p>\n<pre><code>rsync --archive --chown=deploy:deploy ~\/.ssh \/home\/deploy<\/code><\/pre>\n<p>Open a <strong>new<\/strong> terminal window and test the login before you go further. Keep your root session open until this works:<\/p>\n<pre><code>ssh deploy@203.0.113.10\r\nsudo whoami<\/code><\/pre>\n<p><code>sudo whoami<\/code> should print <code>root<\/code> after you enter the user&#8217;s password.<\/p>\n<h2>Step 4: Turn off root login and password logins<\/h2>\n<p>Once key login works for your new user, close the two doors attackers try most often. On Ubuntu, put your settings in a separate file so package updates never overwrite them:<\/p>\n<pre><code>sudo nano \/etc\/ssh\/sshd_config.d\/99-hardening.conf<\/code><\/pre>\n<pre><code>PermitRootLogin no\r\nPasswordAuthentication no\r\nKbdInteractiveAuthentication no<\/code><\/pre>\n<p>Check the configuration and restart SSH:<\/p>\n<pre><code>sudo sshd -t\r\nsudo systemctl restart ssh<\/code><\/pre>\n<p>On Ubuntu 22.04 the service may be called <code>ssh<\/code> or <code>sshd<\/code>. Both names work with <code>systemctl<\/code>. Test a new login as <code>deploy<\/code> in a second window before you close your current session.<\/p>\n<h2>Step 5: Enable the UFW firewall<\/h2>\n<p>UFW is installed on Ubuntu by default but switched off. Allow SSH first, then enable it, otherwise you lock yourself out:<\/p>\n<pre><code>sudo ufw allow OpenSSH\r\nsudo ufw enable\r\nsudo ufw status<\/code><\/pre>\n<p>The status should show <code>OpenSSH ALLOW Anywhere<\/code>. Open more ports only when you install a service that needs them, for example <code>sudo ufw allow 'Nginx Full'<\/code> for a web server.<\/p>\n<h2>Step 6: Set the time zone and automatic security updates<\/h2>\n<p>Correct timestamps make logs readable. List zones with <code>timedatectl list-timezones<\/code> and set yours:<\/p>\n<pre><code>sudo timedatectl set-timezone Europe\/Berlin<\/code><\/pre>\n<p>Ubuntu can install security updates on its own. Make sure it is turned on:<\/p>\n<pre><code>sudo apt install unattended-upgrades -y\r\nsudo dpkg-reconfigure --priority=low unattended-upgrades<\/code><\/pre>\n<p>Choose <strong>Yes<\/strong> when asked whether to download and install stable updates automatically.<\/p>\n<h2>Step 7: Optional extra protection with Fail2ban<\/h2>\n<p>Fail2ban watches your logs and blocks IP addresses that fail to log in too often. With password logins already off it is a second layer rather than a must, but it keeps log noise down:<\/p>\n<pre><code>sudo apt install fail2ban -y\r\nsudo systemctl enable --now fail2ban\r\nsudo fail2ban-client status sshd<\/code><\/pre>\n<h2>Checklist: what your server looks like now<\/h2>\n<table>\n<thead>\n<tr>\n<th>Item<\/th>\n<th>State after this guide<\/th>\n<th>How to check<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Packages<\/td>\n<td>Up to date, security updates automatic<\/td>\n<td><code>apt list --upgradable<\/code><\/td>\n<\/tr>\n<tr>\n<td>Admin user<\/td>\n<td><code>deploy<\/code> with sudo rights<\/td>\n<td><code>groups deploy<\/code><\/td>\n<\/tr>\n<tr>\n<td>SSH login<\/td>\n<td>Keys only, root login off<\/td>\n<td><code>sudo sshd -T | grep -E \"permitrootlogin|passwordauthentication\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Firewall<\/td>\n<td>UFW on, only SSH open<\/td>\n<td><code>sudo ufw status<\/code><\/td>\n<\/tr>\n<tr>\n<td>Brute force protection<\/td>\n<td>Fail2ban active (optional)<\/td>\n<td><code>sudo fail2ban-client status<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>What should you install next?<\/h2>\n<p>Your server is ready for real work. Common next steps on a Cloud VPS Hosts server:<\/p>\n<ul>\n<li>Set up a web server with our guide on <a href=\"https:\/\/cloudvpshosts.com\/kb\/how-to-install-nginx-on-ubuntu\/\">how to install Nginx on Ubuntu<\/a>.<\/li>\n<li>Secure your site with HTTPS: <a href=\"https:\/\/cloudvpshosts.com\/kb\/how-to-generate-a-csr-for-your-ssl-certificate\/\">generate a CSR<\/a>, then <a href=\"https:\/\/cloudvpshosts.com\/kb\/how-to-install-an-ssl-certificate-on-nginx-ubuntu-debian\/\">install the certificate on Nginx<\/a>.<\/li>\n<\/ul>\n<p>Need a fresh Ubuntu server to start with? Our <a href=\"https:\/\/cloudvpshosts.com\/linux-vps.php\">Linux VPS plans<\/a> include full root access and Ubuntu 22.04 and 24.04 images.<\/p>\n<h2>Frequently asked questions<\/h2>\n<h3>I locked myself out after changing SSH settings. What now?<\/h3>\n<p>Open a support ticket from the client area and ask for console access, or use the VNC console in your server panel if your plan includes one. From the console you can log in locally and undo the change in <code>\/etc\/ssh\/sshd_config.d\/99-hardening.conf<\/code>.<\/p>\n<h3>Should I change the SSH port from 22?<\/h3>\n<p>It cuts down automated login attempts in your logs, but it is not real protection on its own. Key-only login and Fail2ban matter much more. If you do change it, allow the new port in UFW before you restart SSH.<\/p>\n<h3>Do these steps work on Debian?<\/h3>\n<p>Almost all of them. On Debian 12, install sudo and UFW first with <code>apt install sudo ufw<\/code>, because they are not always present on minimal images.<\/p>\n<h3>How often should I update the server?<\/h3>\n<p>Unattended upgrades handle security patches daily. Run <code>sudo apt update && sudo apt upgrade<\/code> yourself about once a month to pick up other updates, and reboot when a new kernel is installed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Secure a new Ubuntu 24.04 or 22.04 server: updates, a sudo user, SSH key login, no root login, UFW firewall and automatic security updates.<\/p>\n","protected":false},"author":1,"featured_media":8029,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"","_yoast_wpseo_focuskw":"","rank_math_title":"Initial Server Setup with Ubuntu 24.04 and 22.04 | CVH","rank_math_description":"Set up a new Ubuntu 24.04 or 22.04 server securely: sudo user, SSH keys, root login off, UFW firewall, automatic updates and Fail2ban.","rank_math_focus_keyword":"initial server setup Ubuntu"},"categories":[69],"tags":[226,246,251,240,227],"class_list":["post-8025","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-linux","tag-linux-vps","tag-server-security","tag-tutorial","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/cloudvpshosts.com\/kb\/wp-json\/wp\/v2\/posts\/8025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudvpshosts.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudvpshosts.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudvpshosts.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudvpshosts.com\/kb\/wp-json\/wp\/v2\/comments?post=8025"}],"version-history":[{"count":2,"href":"https:\/\/cloudvpshosts.com\/kb\/wp-json\/wp\/v2\/posts\/8025\/revisions"}],"predecessor-version":[{"id":8327,"href":"https:\/\/cloudvpshosts.com\/kb\/wp-json\/wp\/v2\/posts\/8025\/revisions\/8327"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudvpshosts.com\/kb\/wp-json\/wp\/v2\/media\/8029"}],"wp:attachment":[{"href":"https:\/\/cloudvpshosts.com\/kb\/wp-json\/wp\/v2\/media?parent=8025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudvpshosts.com\/kb\/wp-json\/wp\/v2\/categories?post=8025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudvpshosts.com\/kb\/wp-json\/wp\/v2\/tags?post=8025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}