DEV Community

Ibrahim S
Ibrahim S

Posted on

How I Secured Port 22

SSH is a protocol that allows us to communicate between two computers over the internet (share files, control, or modify remote computers). Its most notable applications are remote login and command-line execution.

Here is the step-by-step process:

  • Install Google Authenticator
  • Configure MFA in PAM
  • Update SSH Configuration
  • Test the setup by logging in again using SSH.

The first step was to install the PAM module for Google Authenticator, which enables Time-based One-Time Passwords (TOTP).
sudo apt update && sudo apt install libpam-google-authenticator
google-authenticator

This generated a QR code I scanned using my authenticator app (like Google Authenticator or Authy) to enable MFA.

The second step was to edit /etc/pam.d/sshd and add this line:
auth required pam_google_authenticator

The third step was to update the SSH configuration.
Edit /etc/ssh/sshd_config and set:
ChallengeResponseAuthentication yes
PasswordAuthentication no
AuthenticationMethods publickey,keyboard-interactive

Restart SSH:
sudo systemctl restart ssh

SSH clients and SSH servers are available for most network operating systems." When you first get acquainted with it, it is most likely presented as a means for accessing a remote server. First of all, that's how it is. However, its capabilities are much wider.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay