DEV Community

Nguyen Trung Duc
Nguyen Trung Duc

Posted on

2 1

Hardening ssh service on Ubuntu/Linux server

Checklist:

  • Disable ssh login for root user
  • Disable password login

1. Create new user

adduser <username>
Enter fullscreen mode Exit fullscreen mode

Add user to sudo group:

usermod -aG sudo <username>
Enter fullscreen mode Exit fullscreen mode

or add this line to file /etc/sudoers.d/90-cloud-init-users (sudo without password)

<username> ALL=(ALL) NOPASSWD:ALL
Enter fullscreen mode Exit fullscreen mode

2. Add ssh key for new user

Add ssh key to file /home/<username>/.ssh/authorized_keys

3. Disable root login and password based login

Edit file /etc/ssh/sshd_config, Find ChallengeResponseAuthentication and set to no:

ChallengeResponseAuthentication no
Enter fullscreen mode Exit fullscreen mode

find PasswordAuthentication set to no:

PasswordAuthentication no
Enter fullscreen mode Exit fullscreen mode

Search for UsePAM and set to no:

UsePAM no
Enter fullscreen mode Exit fullscreen mode

Finally look for PermitRootLogin and set it to no:

PermitRootLogin no
PermitRootLogin prohibit-password
Enter fullscreen mode Exit fullscreen mode

Save and close the file. Reload or restart the ssh server on Linux:

service ssh restart
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay