Hardening your server

Published on: 4th Feb 2021

Updated on: 23th Sep 2022

Why

If your server is public facing (i.e., accessible through the public Internet), then, you will have to follow the checklist below. Basically, it disables all the old and weak features to prevent anyone from exploiting the vulnerabilities.

Here's how you do it

FAQ

What if an user ID needs to have more than one key files

Updated on: 26.Apr.2025

  1. In your computer, you need to generate 2 keys: one for accessing the home computer and another for accessing the work computer.

    ssh-keygen -t rsa -f ~/.ssh/id_rsa.home
    ssh-keygen -t rsa -f ~/.ssh/id_rsa.work
    
  2. Next, add an entry to your ~/.ssh/config file to pick the key to use based on the server you connect to:

    Host home
        Hostname home.example.com
        IdentityFile ~/.ssh/id_rsa.home
        User <your home acct>
        Port 12345
    
    Host work
        Hostname 192.168.1.11
        IdentityFile ~/.ssh/id_rsa.work
        User <your work acct>
        Port 43215
    

    Once you set this up, you may connect to your home computer like this:

    ssh home
    

    To connect your work computer:

    ssh work
    

    In case the remote server still prompted the user password (i.e., it does not use the public key), you need to use -v that will show the connection steps on the screen. This allows you to troubleshoot the password prompting issue.

    ssh work -v
    
  3. Finally, append the contents of your id_rsa.work.pub into ~/.ssh/authorized_keys on the work computer, and do the same for the home key on your home computer.

    In case the same user id has more than 1 key files (in remote server), you may append the key in a separate line.

For the full discussion, visit the following URL: https://serverfault.com/questions/221760/multiple-public-keys-for-one-user

https://linuxize.com/post/using-the-ssh-config-file/

References

Related posts

Back to #UBUNTU blog

Back to #blog listing

Author

Lau Hon Wan, software developer.