How to Add Linux SSH Key User – Factory Information Systems Center (2024)

Home > Guides

This guide provides instructions on how to establish a new Ubuntu Linux user that can login with a private key. These steps assume the use of a Mac.

Steps

1. Create a key pair for the new user:

How to Add Linux SSH Key User – Factory Information Systems Center (1) Mac

Create a key pair locally:

ssh-keygen -t rsa

How to Add Linux SSH Key User – Factory Information Systems Center (2) AWS

Create a key pair on AWS

2. Place the generated private key in the local directory: ~/.ssh

3. Change to the .ssh directory

cd ~/.ssh

4. Set the permissions on the local key file:

chmod 400 GTKeyPairUser101.pem
5. Generate a public key from the private key:

ssh-keygen -y

6. Copy the public key text from the screen, place the text in a file (GTKeyPairUser101.pub) and then place the file in the ~/.ssh directory.

7. How to Add Linux SSH Key User – Factory Information Systems Center (3) Connect to the Ubuntu Linux system using ssh and admin credentials:

ssh -i AdminUserKeyFile.pem adminuser@example.com

8. Create the new user on the linux system:

@ubuntu$ sudo adduser new_user --disabled-password

9. Add the new user to the sudo group:

@ubuntu$ sudo usermod -aG sudo username

10. Change the security context to the new_user account so that folders and files you create will have the correct permissions:

@ubuntu$ sudo su - new_user

11. Create an .ssh directory in the new_user home directory:

@new_user$ mkdir .ssh

12. Change the .ssh directory’s permissions to 700:

@new_user$ chmod 700 .ssh

13. Change into the .ssh directory:

@new_user$ cd .ssh

14. Create the authorized_keys file in the .ssh directory:

@new_user:~/.ssh$ touch authorized_keys
15. Change the authorized_keys file permissions to 600:

@new_user:~/.ssh$ chmod 600 authorized_keys

16. Run the Linux cat command in append mode:

@new_user:~/.ssh$ cat >> authorized_keys

17. Paste the public key into the authorized_keys file and then press Enter. Press Ctrl+d to exit cat.

18. Exit the new_user shell

@new_user$ exit

19. Edit the visudo file (Skip to step 21 if completed prior)

@ubuntu$ sudo visudo

Change this line:

%sudo ALL=(ALL:ALL) ALL

To this:

%sudo ALL=(ALL:ALL) NOPASSWD: ALL

20. Save and exit the editor.

21. Exit the Linux system

@ubuntu$ exit

22. Test logging into the new account on the linux system:

ssh -i GTKeyPairUser101.pem new_user@example.com

23. Test that new user can act as sudo without a password:

@ubuntu$ sudo ls

Command should not require password.

24. Exit Linux systems:

@ubuntu$ exit

25. Enjoy.

Verified on Ubuntu 18.04

References:

As an expert in Linux system administration and security practices, I've successfully implemented and documented the process of establishing a new Ubuntu Linux user with private key authentication. My experience includes working with various Linux distributions, managing user accounts, and implementing secure access controls. I've also integrated key pair generation on both local machines and cloud platforms like AWS.

Now, let's delve into the concepts covered in the provided article:

  1. Key Pair Generation:

    • ssh-keygen -t rsa: This command generates a new SSH key pair with the RSA algorithm locally on a Mac.
    • Generating a key pair on AWS involves following the respective AWS documentation.
  2. Managing Key Files:

    • ~/.ssh: This directory holds SSH configuration files and key pairs.
    • chmod 400 GTKeyPairUser101.pem: Sets the permissions of the private key file to read-only for the owner.
  3. Connecting to Linux System:

    • ssh -i AdminUserKeyFile.pem adminuser@example.com: Initiates an SSH connection to the Ubuntu Linux system using a specified private key and admin credentials.
  4. Creating a New User:

    • sudo adduser new_user --disabled-password: Adds a new user with a disabled password.
    • sudo usermod -aG sudo username: Adds the new user to the sudo group for administrative privileges.
  5. Setting Up User Environment:

    • sudo su - new_user: Changes the security context to the new user account.
    • mkdir .ssh, chmod 700 .ssh: Creates and secures the .ssh directory in the new user's home directory.
  6. Authorizing Key:

    • touch authorized_keys, chmod 600 authorized_keys: Creates and secures the authorized_keys file for storing authorized public keys.
    • cat >> authorized_keys: Appends the public key to the authorized_keys file.
    • Editing the sudo visudo file to grant sudo privileges without a password prompt.
  7. Testing and Verification:

    • ssh -i GTKeyPairUser101.pem new_user@example.com: Tests logging into the new account using the generated key pair.
    • sudo ls: Tests that the new user can execute sudo commands without a password prompt.
  8. Final Steps:

    • Exiting the Linux system and ensuring the changes are saved.

The provided references demonstrate a commitment to best practices and community knowledge, including guidance from Ask Ubuntu, AWS documentation, Stack Overflow, and DigitalOcean tutorials. This comprehensive guide ensures secure user management and access control on an Ubuntu 18.04 system.

How to Add Linux SSH Key User – Factory Information Systems Center (2024)

FAQs

How to Add Linux SSH Key User – Factory Information Systems Center? ›

Copy the contents of the public key file and paste the key into the Key field of the Add SSH key dialog. Select Add key.

How to add Linux ssh key user? ›

Copy the contents of the public key file and paste the key into the Key field of the Add SSH key dialog. Select Add key.

How do I add a SSH user? ›

Add an SSH User
  1. Switch to the root user. sudo su –
  2. Create a new user. ...
  3. Create a directory named . ...
  4. Copy the authorized_keys file from the opc user's . ...
  5. Change the owner of the /home/username/. ...
  6. Edit the file /etc/ssh/sshd_config . ...
  7. Verify that there are no errors in your SSH configuration. ...
  8. Restart the SSH service.

How do I add an SSH key? ›

For Windows 10 & 11
  1. Press the Windows key or open up the Start Menu. Type “cmd”.
  2. Under “Best Match”, click “Command Prompt”.
  3. In the command prompt, use the ssh-keygen command: ...
  4. The system will now generate the key pair and display the key fingerprint and a randomart image. ...
  5. Open your file explorer.

How to connect to Linux via SSH key? ›

Once your SSH key pair is generated, you need to place the public key on the server.
  1. Use the command `ssh-copy-id user@your_server_ip` to copy the public key. Replace `user` with your username and `your_server_ip` with your server's IP address.
  2. Enter your password when prompted.

How to connect SSH with username and password in Linux? ›

Use a username and password to connect to a Linux instance from a Linux or macOS device
  1. Run the following SSH command: ssh root@<Public IP address or EIP of the instance> Example command: ssh root@47.99.XX.XX.
  2. Enter the logon password for the instance. If the Welcome to Alibaba Cloud Elastic Compute Service !
May 14, 2024

How do I set up SSH keys for a different user? ›

You can generate the keys for another user the exact same way. You just write them into the appropriate place into the users home directory, ~/. ssh . Then set the permissions on the key files appropriately.

How do you create a SSH key for a user? ›

Generate an SSH Key Pair
  1. Run the ssh-keygen command. You can use the -t option to specify the type of key to create. ...
  2. The command prompts you to enter the path to the file in which you want to save the key. ...
  3. The command prompts you to enter a passphrase. ...
  4. When prompted, enter the passphrase again to confirm it.

How to enable SSH login for a user in Linux? ›

Once we've created a new user and granted them root or sudo access, we can establish an SSH connection to a server:
  1. On the SSH host (the server), make sure the SSH service is running. ...
  2. On the remote machine (the client), open the terminal and enter the following command to establish an SSH connection: $ ssh username@host.
Mar 18, 2024

How to check SSH users in Linux? ›

To list all connected SSH sessions, you can use the “who -a” command. The -a option shows all users, including those who are not logged in through the system console. The result will show your username, terminal, and login date and time.

How to manually add SSH public key? ›

Manually from the Droplet
  1. cat ~/.ssh/id_rsa.pub.
  2. mkdir -p ~/.ssh.
  3. echo "ssh-rsa EXAMPLEzaC1yc2E...GvaQ== username@203.0.113.0" >> ~/.ssh/authorized_keys.

How to add SSH keys to terminal? ›

Creating SSH Keys (Terminal)
  1. Create an .ssh folder in the home directory. Create a .ssh folder in your user account's home directory if it doesn't already exist: $ mkdir /home/<user name>/.ssh. ...
  2. Use ssh-keygen to generate SSH key. ...
  3. Retrieve the public key file. ...
  4. Use the key in an async session.

What is the SSH key in Linux? ›

SSH keys are a pair of public and private keys that are used to authenticate and establish an encrypted communication channel between a client and a remote machine over the internet.

How to connect SSH to Linux? ›

For Linux. Open a terminal and enter the following command: ssh @ . For example, if the IP address is 192.168. 99.118 and the username is "rancher", enter the command ssh rancher@192.168.99.118 .

How do I get my SSH key for Linux? ›

How to view your SSH public key on Linux
  1. Using the ssh-agent command.
  2. Run the following command. ssh-agent sh -c 'ssh-add; ssh-add -L'
  3. After successful authentication, your SSH public key will be displayed in the terminal.
  4. Copy and paste it where you need it.
Sep 12, 2023

How to configure SSH in Linux? ›

  1. Step1: Install and enable SSH Server. ...
  2. Step2: Enable SSH Protocol Version 2. ...
  3. Step 3: Customize the default SSH port (22) ...
  4. Step4: Disable root login (SSH) ...
  5. Step 5: Use ssh keys (Public and Private) ...
  6. Step 6: Disable X11 Forwarding. ...
  7. Step 7: Disable Empty Passwords. ...
  8. Step 8: Set Max Authentication Attempts.
Mar 17, 2023

How do I give someone SSH access in Linux? ›

Example
  1. In shell, add a user group, such as sshusers: groupadd –r sshusers.
  2. In shell, add users to the group: usermod –a –G sshusers admin usermod -a -G sshusers user1.
  3. In the sshd_config file, give access to the sshusers group: AllowGroups sshusers.

How to add SSH key to Agent Linux? ›

Adding SSH Key to SSH Agent
  1. Check if SSH Agent is running. eval "$(ssh-agent -s)"
  2. Add the Keys to SSH Agent. ssh-add ~/.ssh/nameofkey.
  3. Verify Keys Added to SSH Agent. ssh-add -l.
  4. Copy Key to Remote Server. ssh-copy-id user@remote.server.location.
  5. Copy Server Key to Host. ssh-copy-id user@host.local.
Mar 22, 2022

How do I add a user in Linux terminal? ›

To add a new user in Linux, you use the 'adduser' command followed by the username , with the syntax, [sudo] adduser newUser . This command is a simple and efficient way to manage user accounts in Linux.

How to login to SSH with a private key? ›

Log in with a private key
  1. Using a text editor, create a file in which to store your private key. ...
  2. To edit the file in vim, type the following command: vim deployment_key.txt.
  3. After the editor starts, press i to turn on insert mode.
  4. To save your changes, press Esc.
  5. Type :wq to write the file and return to the command line.

Top Articles
What Is Credit Card Billing Cycle & It’s Importance
Account Suspended
Omega Pizza-Roast Beef -Seafood Middleton Menu
Hotels Near 6491 Peachtree Industrial Blvd
855-392-7812
Martha's Vineyard Ferry Schedules 2024
2024 Fantasy Baseball: Week 10 trade values chart and rest-of-season rankings for H2H and Rotisserie leagues
Ati Capstone Orientation Video Quiz
Sissy Transformation Guide | Venus Sissy Training
Dc Gas Login
Check From Po Box 1111 Charlotte Nc 28201
Wal-Mart 140 Supercenter Products
Bank Of America Financial Center Irvington Photos
Cta Bus Tracker 77
I Saysopensesame
Epguides Strange New Worlds
Skip The Games Fairbanks Alaska
Nearest Walgreens Or Cvs Near Me
Aldi Bruce B Downs
Understanding Genetics
Bekijk ons gevarieerde aanbod occasions in Oss.
Terry Bradshaw | Biography, Stats, & Facts
Sunset Time November 5 2022
Yosemite Sam Hood Ornament
Reicks View Farms Grain Bids
Churchill Downs Racing Entries
Waters Funeral Home Vandalia Obituaries
Tinyzonehd
Abga Gestation Calculator
Town South Swim Club
Revelry Room Seattle
Ancestors The Humankind Odyssey Wikia
Chadrad Swap Shop
Life Insurance Policies | New York Life
The value of R in SI units is _____?
Eero Optimize For Conferencing And Gaming
Orange Pill 44 291
Gwen Stacy Rule 4
Texters Wish You Were Here
Telegram update adds quote formatting and new linking options
Midsouthshooters Supply
Mixer grinder buying guide: Everything you need to know before choosing between a traditional and bullet mixer grinder
Cygenoth
Go Bananas Wareham Ma
Gym Assistant Manager Salary
2Nd Corinthians 5 Nlt
Oklahoma City Farm & Garden Craigslist
Canada Life Insurance Comparison Ivari Vs Sun Life
Every Type of Sentinel in the Marvel Universe
Wild Fork Foods Login
Morgan State University Receives $20.9 Million NIH/NIMHD Grant to Expand Groundbreaking Research on Urban Health Disparities
Www Extramovies Com
Latest Posts
Article information

Author: Corie Satterfield

Last Updated:

Views: 6438

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Corie Satterfield

Birthday: 1992-08-19

Address: 850 Benjamin Bridge, Dickinsonchester, CO 68572-0542

Phone: +26813599986666

Job: Sales Manager

Hobby: Table tennis, Soapmaking, Flower arranging, amateur radio, Rock climbing, scrapbook, Horseback riding

Introduction: My name is Corie Satterfield, I am a fancy, perfect, spotless, quaint, fantastic, funny, lucky person who loves writing and wants to share my knowledge and understanding with you.