HOWTO - Create New SSH User

 

Create a New SSH User:

  • Create a new user on your server for the person who needs to SSH in. You can do this using the adduser command. For example:


        sudo adduser newuser
    
Follow the prompts to set up a password and other details for the new user.

Grant Sudo Privileges (Optional):

  • If the user needs administrative privileges, you can add them to the sudo group. This allows them to execute commands with superuser privileges. Use the usermod command:


    sudo usermod -aG sudo newuser

  1. Provide Public Key:

    • Ask the user to generate an SSH key pair on their local machine (if they haven't already) using the ssh-keygen command. They will have a private key (usually named id_rsa) and a public key (usually named id_rsa.pub).

  2. Send Public Key to You:

    • Have the user send you their public key. This is typically the content of the id_rsa.pub file. They can use a secure method like encrypted email or a secure messaging platform.

  3. Add Public Key to Authorized Keys:

    • On your server, navigate to the home directory of the new user and create a .ssh directory if it doesn't exist:

    sudo mkdir /home/newuser/.ssh

Open or create the authorized_keys file:

    sudo nano /home/newuser/.ssh/authorized_keys

Paste the content of the user's public key into this file. Set the correct ownership and permissions:

sudo chown newuser:newuser /home/newuser/.ssh/authorized_keys
sudo chmod 600 /home/newuser/.ssh/authorized_keys

Test the Setup:

  • Have the user try to SSH into the server using their private key:


ssh -i /path/to/private_key newuser@your_server_ip

  1. Replace /path/to/private_key with the actual path to their private key and your_server_ip with the IP address or domain of your server.

This way, you maintain better control over access to your server, and each user has their own set of keys for authentication. It's a good security practice as it allows you to grant or revoke access for individual users without affecting others.


Comments

Popular posts from this blog

Obtaining Google Application Credentials for Python Development: A Comprehensive Guide

Flask 101

HOWTO - SSH via Mac Terminal