This guide will walk you through the process of creating SSH key pairs for secure login without a password on Internetport's servers. We'll cover how to generate keys on both Windows using PuTTYgen and ssh-keygen, as well as on Linux and macOS systems. Additionally, we'll show you how to add your public key to the server and disable password authentication for enhanced security.

Generating SSH Key Pairs

On Windows

You can generate SSH keys using either PuTTYgen (a graphical tool) or ssh-keygen (via Git Bash or WSL).

Using PuTTYgen

  1. Download and install PuTTY from the official website.
  2. Open PuTTYgen, select SSH-2 RSA as the type of key to generate, and click "Generate". Move your mouse around in the blank area to provide randomness for the key generation process.
  3. Enter a passphrase (optional but recommended) and confirm it. Click "Save public key" and "Save private key" to save them on your computer.

Using ssh-keygen via Git Bash or WSL

  1. Open Git Bash (part of the Git for Windows suite) or Windows Subsystem for Linux (WSL).
  2. Run the following command to generate a key pair:
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  3. Press Enter to accept the default file location, or specify another path. Enter and confirm a passphrase when prompted.

On Linux and macOS

  1. Open your terminal.
  2. Run the following command:
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  3. Press Enter to accept the default file location, or specify another path. Enter and confirm a passphrase when prompted.

Adding Your Public Key to the Server

  1. Copy your public key to the clipboard:
    • Windows: Open the file in Notepad and copy its contents.
    • Linux/macOS: Use the following command:
      xclip -sel clip < ~/.ssh/id_rsa.pub
      or
      pbcopy < ~/.ssh/id_rsa.pub
  2. Log in to your server using SSH and a password.
  3. Create the .ssh directory if it doesn't exist:
    mkdir -p ~/.ssh
  4. Add your public key to the authorized_keys file:
    echo "your_public_key" >> ~/.ssh/authorized_keys
    Replace "your_public_key" with the contents of your clipboard.
  5. Set the correct permissions for the .ssh directory and authorized_keys file:
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys

Disabling Password Authentication (Optional but Recommended)

To enhance security, you can disable password authentication on your server.

  1. Edit the SSH daemon configuration file:
    nano /etc/ssh/sshd_config
  2. Find and modify the following lines:
    PasswordAuthentication no
    ChallengeResponseAuthentication no
    UsePAM no
  3. Save the file and restart the SSH service:
    • Debian/Ubuntu:
      sudo systemctl restart sshd
    • CentOS/RHEL:
      sudo systemctl restart sshd

Troubleshooting

  • Permission denied (publickey): Ensure your public key is correctly added to the authorized_keys file and that the permissions are set as described.
  • Server refused our key: Verify that you're using the correct private key for authentication. You can specify it with the -i option:
    ssh -i /path/to/private_key user@hostname
  • Connection refused: Check if SSH is running on your server and that you're using the correct hostname or IP address.

By following these steps, you can securely log in to your Internetport servers without a password, enhancing both convenience and security.