Author Topic: SSH access for a non-root user  (Read 8189 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
SSH access for a non-root user
« on: June 28, 2018, 10:25:31 PM »
I can't seem to find any information regarding my question.

I can connect to my server at root using SSH using key-based authentication.

But I am am also trying to setup SSH access for a non-root user on the server.

Shell access is checked ✓ under Edit User.

Ideally I would like to use a unique SSH key for this user, but I have no idea how to set that up.

In the meanwhile, I am trying to connect as that user. But I receive

Code: [Select]
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
If I try and connect using the root's key I receive

Code: [Select]
Server refused our key
What am I missing?


Offline
*
Re: SSH access for a non-root user
« Reply #1 on: June 28, 2018, 10:37:33 PM »
Nevermind. Figured it out. I'll share the solution for some other noob who is sure to ask the same question.

I just needed to create a keypair using ssh-keygen -f <username> which put username and username.pub in my user's /home/.ssh directory.

I then had to create a file called authorized_keys in the same directory and copy the contents of username.pub into it.

I then use the username file as the private key when connecting as username@domain.com from PuTTy/BitVise/MobaXterm/etc.
« Last Edit: June 28, 2018, 10:57:06 PM by stevland »

Offline
*
Re: SSH access for a non-root user
« Reply #2 on: September 13, 2019, 12:34:44 AM »
Thanks Stevland!

Offline
*
Re: SSH access for a non-root user
« Reply #3 on: May 01, 2021, 09:18:05 AM »
Thank you stevland for your reply.
I just want to make your answer more clear.
1. Create the .ssh directory in the /home/username first
2. Then create a key pair while logged in as root user using the command
Code: [Select]
ssh-keygen -t rsa -f /home/username/.ssh/<key_name>This will result in two files in the /home/username/.ssh directory namely <key_name> and <key_name>.pub
Then add the contents of the key_name.pub file to the authorized_keys file using the command
Code: [Select]
cat  /home/username/.ssh/<key_name>.pub> /home/username/.ssh/authorized_keysThen you can use the username and the <key_name> file to login via ssh without any issues

This particularly applies to the cloud servers where the ssh access is allowed ony using the key files.