ThisIsJo(e).com

Hello, this is my blog, where I document my thoughts and opinions. My current professional passions are cybersecurity, Linux, and networking.

Setting Up SSH with Static IP and Agent Config

Intro:

For this SSH server I’m using Debian 12 in a VM using Proxmox. This guide should work if you using a fresh install of Debian just make sure you at least give you user sudoers permissions and install sudo.

1. Install OpenSSH Server

  • Install the OpenSSH server on the remote machine.

2. Confirm SSH Access

  • Verify you can log in to the server:

3. Generate RSA Keys

  • Were using these keys to protect against brute force attacks and set up ssh-agent later on this guide. I’m using RSA because I’m used to it but if you want a strong and faster Cryptography you can use Ed25519. Both of these use asymmetric cryptography so this guide doesn’t change much if you do choose to use ED25519. If you’r clueless about asymmetric cryptography I would go ahead and read this before continuing. https://www.techtarget.com/searchsecurity/definition/asymmetric-cryptography
  • NEVER SHARE YOU PRIVATE KEY WITH ANYONE!
  • Run the following command to generate RSA keys:

Explanation of options:

  • -t rsa: Specifies the use of RSA encryption.
  • -b 4096: Sets the key size to 4096 bits.
  • -f: Defines the name and location of the key file.
  • -C: Adds a comment to identify the key.
  • Default location: ~/.ssh/id_rsa.

4. Transfer the Public Key

  • Use the following command to copy the public key to the server:

Explanation:

  • -i: Specifies which key to use.
  • Automatically creates the .ssh directory and appends the public key to the ~/.ssh/authorized_keys file on the server.
    Example:
  • You can use the -i: to specifies where the key is at but it should do this by default.

5. Edit SSH Server Configuration

  • This stop logging in using the password instead of the keys we generated.
  1. Open the SSH configuration file on the server:
  1. Add the following lines to disable password authentication:

6. Set a Static IP Address

  • Avoid confusion if this changes later on and is needed later on the guide.
  1. Exit the SSH session and log into the server locally or via SSH.
  2. Identify the network interface:
  1. Edit the network interfaces file:
  1. Add the following under the primary network interface:
  1. Restart the networking service and reboot:
  1. Verify the IP address after reboot:

7. Use SSH Agent for Passwordless Login

  • Reduce the headache of remembering the ssh keys passwords. I would still recommend you storing these password somewhere safe just in case you lose the private keys.
  1. Start the SSH agent and add your private key:
  1. This allows you to log in without entering the passphrase for the key every time.

8. Automate SSH Agent with Config File

  1. Remember that the eval $(ssh-agent) command needs to be run each time unless automated.
  2. To simplify logins, create an SSH config file:
  1. Add configuration for each server:

Example:

  1. Now you can connect to the servers with just the host alias:

Leave a Reply

Your email address will not be published. Required fields are marked *