Quickstart cipi.yml Web panel API MCP Ecosystem Guides Docs GitHub Telegram channel
  1. Home
  2. Guides
  3. SSH security for your servers: keys, a closed port 22, tunnels and alerts
Security

SSH security for your servers: keys, a closed port 22, tunnels and alerts

SSH is the front door of your server. Cipi locks it at install; this guide shows what is already done, what to add, and how to take port 22 off the internet without ever locking yourself out.

By Updated 8 min read

SSH is how you, your team and sometimes your CI reach a server. Bots try it all day long: within minutes of a VPS going online, its log fills with guesses for root, admin and ubuntu. On a Cipi server those guesses can't work — but there is still a lot you can do to make SSH quiet, auditable and, in the end, invisible to the internet.

Key ideas, in plain words#

TermMeaning
SSH keyA pair of files: the private key stays on your laptop, the public key goes on the server. Whoever has the private key gets in
PassphraseA password that encrypts the private key on your disk, so a stolen laptop isn't a stolen server
cipi userThe admin entry point. You log in as cipi and run sudo cipi …; root can't log in over SSH
App userEach app is a Linux user (shop, blog). It can get SSH or SFTP of its own, per app
Fail2banBans an address that keeps failing logins, a little longer each time
Port 22Where SSH listens. Open to the world by default, so you can log in after install
LockClosing port 22 to the world while it stays open on a private network (Tailscale, NetBird) or through Cloudflare
SSH tunnelUsing an SSH connection to reach a service that is closed to the internet, such as the database
Step 1 of 6Keys only

No passwords, no root login, three tries per connection: guessing is useless from the first minute.

What Cipi already did at install#

You don't have to touch sshd_config. The installer writes:

SettingValueWhat it means
PermitRootLoginnoNobody logs in as root over SSH
PasswordAuthenticationnoKeys only for the admin user: there is no password to guess
PubkeyAuthenticationyesKeys are how you get in
PermitEmptyPasswordsno—
MaxAuthTries3Three attempts per connection, then it's cut
LoginGraceTime20Twenty seconds to finish logging in
X11ForwardingnoNo graphical forwarding
AllowGroupscipi-ssh cipi-appsOnly the admin user and app users may log in at all

Plus UFW (only SSH, 80 and 443 open), Fail2ban on SSH, and a key-only cipi user that runs exactly one thing as root without a password: the cipi command. Check it any time:

bash
sudo cipi firewall status        # what is open, who holds each port
su root                          # a root shell (the root password is in the install summary)
# sshd -T | grep -Ei '^(permitrootlogin|passwordauthentication|maxauthtries|allowgroups)'

Edit /etc/ssh/sshd_config only above Cipi's managed block (# >>> cipi ssh apps): Cipi rewrites that block on updates, and validates every change it makes with sshd -t before reloading, so a typo never replaces a working configuration.

1. Use good keys, and look after them#

On your laptop:

bash
ssh-keygen -t ed25519 -C "andrea@laptop"     # set a passphrase when asked
ssh-add --apple-use-keychain ~/.ssh/id_ed25519   # macOS: unlock once per session (Linux: ssh-add)
cat ~/.ssh/id_ed25519.pub                    # the public key, the one you give the server

On the server, one key per person and per device, each with a name you'll recognise in a year:

bash
sudo cipi ssh add "ssh-ed25519 AAAAC3Nz… mario@workstation"
sudo cipi ssh list                  # keys, fingerprints, the one you're using now
sudo cipi ssh rename 2 "mario-workstation"
sudo cipi ssh remove 2              # Mario left: his key goes, for every app at once
GuardWhy it matters
You can't remove the key of your own sessionNo accidental lock-out
You can't remove the last keyThe server always has a way in
Format and duplicate checksNo broken or repeated keys
A notification for every add, remove and renameA key that appears out of nowhere is noticed

Good habits that cost nothing:

  • Never share a private key. Two people, two keys: when one leaves, only theirs goes.
  • Don't forward your agent (ForwardAgent yes) to servers. To hop through one machine, use ProxyJump instead.
  • Check the server's fingerprint the first time you connect. Read it once from the provider's console: ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub.
  • Give your laptop a short ~/.ssh/config, so the right key is always used:
text
Host prod
  HostName 203.0.113.10
  User cipi
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes

Then ssh prod, and sudo cipi status.

2. App users: SSH and SFTP only where needed#

Every app is its own Linux user, and the server's admin keys always open a shell as any of them (ssh shop@server). Whether an app also accepts its own password and keys from outside — for a client's SFTP upload, for example — is decided per app:

bash
sudo cipi ssh apps                  # every app: enabled or disabled
sudo cipi ssh apps enable blog      # the client uploads to blog over SFTP
sudo cipi ssh apps disable blog     # done: admin keys only again
sudo cipi ssh apps disable --all    # every app, and new apps from now on

New servers create apps disabled. Deploys are never affected: they connect to localhost. Password reset for an app user, when you do enable it: sudo cipi app reset-password blog. Details: App users' SSH and SFTP.

3. Let Fail2ban (and CrowdSec) deal with guessers#

Fail2ban bans an address after 3 failed logins within an hour, and a little longer each time it comes back. Tune it, and look at who's banned:

bash
sudo cipi firewall attempts         # the current threshold
sudo cipi firewall attempts 5       # more forgiving, for a team on shared IPs
sudo cipi ban list                  # who is banned now (Fail2ban and CrowdSec together)
sudo cipi ban unban 198.51.100.23   # a colleague who fat-fingered a passphrase

For the web and SSH, CrowdSec adds behaviour detection and a community blocklist of known attackers, with your own SSH session allowlisted before it starts. The panel's Firewall tab shows UFW, Fail2ban and CrowdSec together, each ban with Unban.

4. Be told about every login#

A ban says someone knocked. A login alert says someone got in — and that's the one you want on your phone. Cipi sends a security notification for:

TriggerWhen
ssh_loginAn SSH login of cipi, root or a sudoer — with source IP and key fingerprint
sudo, suSomeone became root
ssh_key_add, ssh_key_remove, ssh_key_renameThe keys that open the server changed
credentials_showSomeone printed or exported the server's credentials

Send them where you'll see them:

bash
sudo cipi notification add telegram oncall --token=<bot-token> --chat-id=<chat-id>
sudo cipi notification events oncall urgent    # failures and security events only
sudo cipi notification test oncall

An alert for a login you didn't make is your cue: remove the key (sudo cipi ssh remove), check sudo cipi ssh list, and read Notifications for routing everything else. Step by step: Server notifications done right.

5. Keep CI off SSH#

A CI runner with an SSH key for cipi can run any cipi command. Most pipelines only need to deploy, so give them exactly that:

bash
sudo cipi api token create --name=github-actions --abilities=deploy-manage --expires=2027-06-30

The pipeline calls the REST API over HTTPS with that token: no SSH key on the runner, nothing to steal that could do more than a deploy. Or skip CI access altogether and deploy on push with the Cipi Agent's signed webhook. Recipes for both: CI/CD pipelines.

6. Close port 22 to the internet#

With keys only and Fail2ban, port 22 is safe — but it is still there, for every scanner and for the next OpenSSH vulnerability. The best SSH port is one the internet can't reach. Cipi gives you two ways, and both keep port 22 itself: only who can reach it changes.

Tailscale or NetBird (mesh)Cloudflare Tunnel + Access
How you connectssh cipi@100.101.102.103 from any device on your private networkssh cipi@ssh.example.com, through Cloudflare, after signing in
What you install on your laptopThe Tailscale or NetBird clientcloudflared
Second factorYour identity provider's login for the network; optional Tailscale SSHCloudflare Access login, optional short-lived certificates instead of keys
Best forYou and your team reaching serversTeams already on Cloudflare; SSH next to sites published through the tunnel

Which one fits, in detail: Cloudflare Zero Trust vs Tailscale vs NetBird.

With Tailscale or NetBird#

bash
sudo cipi zt tailscale enable --auth-key=tskey-auth-…    # or: sudo cipi zt netbird enable --setup-key=…
sudo cipi zt tailscale status                            # the server's address on the network
Step 1 of 3Join

It closes nothing: port 22 still answers the world.

bash
ssh cipi@100.101.102.103                # from your laptop, on the tailnet
sudo cipi zt tailscale lock ssh         # port 22 now answers on the mesh only
sudo cipi zt tailscale unlock ssh       # back to the world, if you ever need it

Full walkthrough: Reach your servers over Tailscale or NetBird.

With Cloudflare#

bash
sudo cipi zt ssh enable --hostname=ssh.example.com   # SSH through the tunnel, behind Access

On your laptop, ~/.ssh/config (the command prints it for you):

text
Host ssh.example.com
  ProxyCommand cloudflared access ssh --hostname %h
  User cipi
  IdentityFile ~/.ssh/id_ed25519

Then ssh ssh.example.com — a browser tab asks you to sign in once — and only when that works:

bash
sudo cipi zt lock ssh --yes      # port 22 closed to the world

Want to stop managing keys altogether? Short-lived certificates: Access signs a certificate for each login, valid for minutes, tied to the person's email.

bash
sudo cipi zt ssh cert enable --principals=andrea,mario
cloudflared access ssh-config --hostname ssh.example.com --short-lived-cert >> ~/.ssh/config   # on your laptop

Full walkthrough: Put a Laravel server behind Cloudflare Zero Trust.

Lock SSH only from a session that already came through the new way in, and keep your provider's web console at hand. sudo cipi firewall refuses to reopen a port a lock holds, and names the command that does.

7. Reach the database through SSH, not through an open port#

Never open 3306 or 5432 to the internet. Your SSH connection can carry the database instead:

bash
# a local port 3307 that leads to MariaDB on the server
ssh -N -L 3307:127.0.0.1:3306 prod
# in another terminal, or in your database client
mysql -h 127.0.0.1 -P 3307 -u shop -p shop

TablePlus, DBeaver, Sequel Ace and DataGrip do the same in their Over SSH option: SSH host prod (or the mesh address), database host 127.0.0.1, the app's database user and password. With port 22 locked to a mesh, the tunnel simply runs over the mesh. Behind Cloudflare, sudo cipi zt tcp add mysql --hostname=db.example.com puts the database behind Access instead, and cloudflared access tcp gives you the local port (TCP services).

For a copy of production on your laptop without anyone's personal data, use the anonymizer rather than a raw dump.

8. Plan your way back in#

You lost…Way back
Your IP (banned)Wait for the ban to expire, or connect from another network and sudo cipi ban unban <ip>
Your IP, with CrowdSec onThe rescue command you stored off the server: sudo cipi crowdsec rescue token prints it (rescue)
Your laptop's keyA teammate's key, or the provider's web console; then sudo cipi ssh add a new key and sudo cipi ssh remove the old one
The mesh or CloudflareThe provider's web console, then sudo cipi zt tailscale unlock ssh or sudo cipi zt ssh unlock

Write down where the provider's console is (Hetzner, DigitalOcean, AWS all have one) before you need it.

Checklist#

Check
☐Ed25519 keys with a passphrase, one per person and device, named (sudo cipi ssh list)
☐Former team members' keys removed
☐App users' SSH disabled where nobody needs SFTP (sudo cipi ssh apps)
☐Login and key alerts on a channel you read (sudo cipi notification events)
☐CI deploys with an API token that can only deploy, not with an SSH key
☐Port 22 locked to Tailscale, NetBird or Cloudflare
☐The database reached through SSH, never on an open port
☐The provider's web console tested once

Troubleshooting#

ProblemFix
Permission denied (publickey)The key on your laptop isn't on the server: ssh -v shows which key is offered. Add the right one with sudo cipi ssh add from a working session
Asked for a password as cipiYou're offering no key: check IdentityFile and ssh-add -l
Connection times out after a few triesFail2ban banned your IP: from elsewhere, sudo cipi ban list and sudo cipi ban unban <ip>
lock ssh refusedCipi hasn't seen a login over the mesh or the tunnel yet: log in that way first, from that session lock
An app user can't log in with its passwordSSH for that app is disabled: sudo cipi ssh apps enable <app>
SFTP client fails but SSH worksUse the app user (blog@server), not cipi, and the path /home/blog/htdocs

Questions

Is SSH on port 22 unsafe?

Not with keys only, which is how Cipi sets it up: bots knock all day and get nowhere. The risk left is the noise, a stolen key and the next OpenSSH bug. Closing port 22 to the world with a private network or Cloudflare removes all three from the internet.

Should I move SSH to another port?

It cuts log noise and nothing else: a port scan finds it in seconds. Cipi doesn't change the port for you. If you want SSH off the internet, close it with a lock (step 6): the port stays 22, and only your devices can reach it.

Can I log in as root?

Not over SSH: the installer sets PermitRootLogin no. Log in as cipi and type sudo cipi …; for a root shell, su root with the root password from the install summary.

Can I use a password instead of a key?

Not for the admin user: passwords are off (PasswordAuthentication no). An app user can get a password for SFTP if you allow it per app (sudo cipi ssh apps enable shop).

Which key type?

Ed25519, protected by a passphrase. cipi ssh add takes ssh-ed25519, ecdsa-sha2-* and ssh-rsa; for a second factor use Cloudflare's short-lived certificates or Tailscale SSH (step 6).

How do I know someone logged in?

Every SSH login of cipi, root or a sudoer, every sudo and su, and every key added or removed is a security notification, with source IP and key fingerprint. Send them to Telegram or Slack with sudo cipi notification events <channel> urgent.

I banned myself. What now?

Wait for the Fail2ban ban to expire, connect from another network, use the CrowdSec rescue if you enabled CrowdSec, or open your provider's web console and run sudo cipi ban unban <your-ip>.

Do deploys need port 22?

No. Webhook deploys run on the server, and deploys from CI can go through the REST API with a token that may only deploy. Deploys use SSH to localhost, which no lock closes.

Try it on your own server

Free and open source. One command on a fresh Ubuntu 24.04 or 26.04 VPS.

wget -O - https://cipi.sh/setup.sh | bash
Read the quickstart