# First-day VDS security: SSH key and firewall

https://trecloud.com.tr/en/knowledgebase/article/vds-ilk-gun-ssh-anahtari-ve-guvenlik-duvari

Your new VDS has been delivered; you have an IP address and a root password. The few settings you make in the first hour shape the server's next months. This article gives the first-day VDS security steps for Ubuntu 24.04 in order: updates, a sudo user, an SSH key, password-less login, a firewall and recovery if you lock yourself out.

![Cover image about setting up an SSH key and the ufw firewall on an Ubuntu 24.04 VDS](https://trecloud.com.tr/resources/uploads/articles/2026-11-24/vds-ilk-gun-ssh-anahtari-ve-guvenlik-duvari.jpg)

**Contents**

1. [Get the details and connect](#baglanma)
2. [Create a sudo user](#kullanici)
3. [Create an SSH key](#anahtar)
4. [Turn off password login](#sshd)
5. [Firewall: ufw](#ufw)
6. [Automatic updates and fail2ban](#guncellemeler)
7. [If you get locked out: Console](#kurtarma)

## Get the details and connect

In the customer panel, click the **Management** button of your VDS under **My Services**. The **Service Information** box shows the IP address, the user name (root) and a hidden password field; password actions are under **Password management** in **Quick Actions**. The whole screen is described in the [VDS customer panel article](https://trecloud.com.tr/bilgi-bankasi/makale/vds-musteri-panelinden-yonetim).

Connect from your own computer and update the packages. Replace the IP in the examples below with your own address. On the first connection you are asked to confirm the server's fingerprint.

```
ssh root@203.0.113.10
apt update && apt upgrade -y
```

If the kernel was updated, restart the server with `reboot`.

## Create a sudo user

Do daily work with your own user instead of root. You can use any name instead of `deploy`; `adduser` asks for a password, which is used for `sudo`.

```
adduser deploy
usermod -aG sudo deploy
```

## Create an SSH key

Generate the key pair on your own computer, not on the server. On Linux and macOS:

```
ssh-keygen -t ed25519 -C "dizustu"
ssh-copy-id deploy@203.0.113.10
```

On Windows, PowerShell knows `ssh-keygen` but has no `ssh-copy-id`. You can send the public key with this command:

```
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh deploy@203.0.113.10 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
```

Now confirm that you can log in without a password with `ssh deploy@203.0.113.10` and that `sudo -v` works. Do not move on until both tests succeed.

## Turn off password login

On Ubuntu 24.04, `/etc/ssh/sshd_config` reads the `.conf` files under `/etc/ssh/sshd_config.d/` first, and if a setting appears more than once, the first value read wins. So start the file name with `00`; that way it comes before files such as `50-cloud-init.conf` left by cloud images.

```
sudo tee /etc/ssh/sshd_config.d/00-guvenlik.conf >/dev/null <<'EOF'
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
EOF
sudo sshd -t && sudo systemctl restart ssh
sudo sshd -T | grep -Ei 'passwordauthentication|permitrootlogin'
```

The last command should show `passwordauthentication no` and `permitrootlogin without-password`; `without-password` is the old name of the `prohibit-password` setting. On Ubuntu 24.04 the SSH service is called `ssh`. Important: without closing your open session, try logging in with `ssh deploy@203.0.113.10` in a new terminal. If something is wrong, you fix it from the open session. If you never want root to log in over SSH, write `no` instead of `prohibit-password`.

## Firewall: ufw

Allow SSH first, then enable the firewall; in the reverse order your connection drops. If you will not run a web server, skip the 80 and 443 line.

```
sudo ufw allow OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw enable
sudo ufw status verbose
```

The network filter in front of the server filters attack traffic at network level; ufw decides which ports the server itself talks on. One does not replace the other. If you use Docker, be aware that published container ports can bypass ufw rules. For details see the [Ubuntu UFW documentation](https://help.ubuntu.com/community/UFW).

## Automatic updates and fail2ban

Install and enable the `unattended-upgrades` package so that security patches are installed automatically. Ubuntu server installations often ship with it already; the command does no harm.

```
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
```

fail2ban is optional. With password login off it adds less, but it keeps the logs clean of repeated attempts. The Ubuntu package enables SSH protection (the sshd jail) by default:

```
sudo apt install fail2ban
sudo fail2ban-client status sshd
```

## If you get locked out: Console

If a wrong setting has closed the SSH door, open the server's screen in the browser with **Quick Actions › Console** in the panel. The console does not depend on SSH settings; you log in as root with its password. If you do not remember the password, use **Password management**. Undo the faulty setting in the console:

```
rm /etc/ssh/sshd_config.d/00-guvenlik.conf
systemctl restart ssh
ufw allow OpenSSH
```

**Format** is the last resort: it reinstalls the operating system from scratch and deletes all data. This is an unmanaged service; patching, monitoring and backups are your responsibility, while infrastructure support runs 24/7. If you have not decided yet, see the [hosting or VDS decision tree](https://trecloud.com.tr/hosting-mi-vds-mi-8-soruluk-karar-agaci).

## Frequently asked questions

Should I change the SSH port from 22?It is not required; the real protection is key-based login with password login turned off. If you change it, on Ubuntu 24.04 SSH starts from a socket, so open the new port in ufw and run systemctl daemon-reload and systemctl restart ssh.socket. Which password do I use in the console?The console is not SSH; you log in as root with the root password. You manage that password under Password management in the panel. Why does ssh-copy-id not work on Windows?The OpenSSH client on Windows has no ssh-copy-id. The PowerShell command in this article adds the public key to the server in the same way. Will TreCloud do these steps for me?On an unmanaged VDS the operating system settings are yours; patching, monitoring and backups are a separate item in the managed service. You get 24/7 support for infrastructure issues.

## Related pages

- [Cloud server and VDS packages](https://trecloud.com.tr/bulut-sunucu)
- [Connecting to a server with SSH](https://trecloud.com.tr/bilgi-bankasi/makale/ssh-ile-sunucuya-baglanma)
- [Managing a VDS from the customer panel](https://trecloud.com.tr/bilgi-bankasi/makale/vds-musteri-panelinden-yonetim)
- [First-day firewall: 22, 80, 443](https://trecloud.com.tr/ilk-gun-guvenlik-duvari-22-80-443)
- [Hosting or VDS? An 8-question decision tree](https://trecloud.com.tr/hosting-mi-vds-mi-8-soruluk-karar-agaci)

Written by TreCloud Team · TRE Teknoloji · November 9, 2026
