How to create an SSH user on Ubuntu 24.04lts

To create an SSH user on Ubuntu 24.04lts and restrict access using the AllowUsers directive without using SSH keys, follow these steps:

    • sudo adduser <user-name>

Follow the prompts to set a password and fill in any additional user information.

2. Update SSH Configuration: Open the SSH configuration file in a text editor:

    • sudo vi /etc/ssh/sshd_config

3. Find the #AllowUsers line (if it exists) and uncomment it. Then, add your new user to the list. If there is not a line containing AllowUsers add it.

For example:

    • AllowUsers user1 user2 newuser

If there are other users listed, you can separate them with spaces:

4. Password Authentication: Make sure password authentication is enabled in the SSH configuration.

    • Uncomment “PasswordAuthentication yes” by removing the hashtage from in front of it.

5. Restart the SSH Service: After saving the changes, restart the SSH service to apply them:

    • sudo systemctl restart ssh

6. Test SSH Access: From a different terminal or machine, try to SSH into your Ubuntu server using the new user:

    • ssh newuser@your_server_ip

You should be prompted for the password you set earlier.

7. Important Considerations

    • Firewall Rules: Ensure that your firewall allows SSH connections (typically on port 22).
    • Security: Using password authentication can be less secure than using SSH keys. Consider setting up key-based authentication if possible.

That’s it! You’ve created an SSH user and restricted access using AllowUsers.