How to SSH with multiple users to my ubuntu server

facelessgreyhat 21 Reputation points
2020-08-22T12:04:52.653+00:00

Wondering how to SSH with multiple users to my ubuntu server ? Adding public key under .ssh/authorized_keys doesn't help for 2nd user. It only allows the user which has been configured from the portal.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
0 comments No comments
{count} votes

Accepted answer
  1. vipullag-MSFT 26,487 Reputation points Moderator
    2020-08-24T11:00:23.5+00:00

    @facelessgreyhat

    I just tested your ask on Ubuntu VM with the same approach as you mentioned by adding multiple ssh pub keys under .ssh/authorized_keys and it is allowing multiple user login without any issue.

    Managing multiple logins to Ubuntu Azure VM is no different as it is OS level operation.

    Here are few checks that I would request you to validate on your end.

    • Ensure that the PubkeyAuthentication yes is enabled in /etc/ssh/sshd_config file
    • Restart the ssh service once you add the second public key in ~/.ssh/authorized_keys

    Below are the repro steps for your reference :

    • Created a Azure Ubuntu VM with password auth for testing this ask
    • Created ssh key using ssh-keygen -t rsa -b 2048 from another Ubuntu env (local Ubuntu instance) with a user1
    • Copied the pub key created in the previous step to the Azure Ubuntu VM
    • Added the copied pub key to authorized_keys cat id_rsa.pub >> ~/.ssh/authorized_keys
    • Enabled the PubkeyAuthentication yes in /etc/ssh/sshd_config file
    • Restarted the ssh service sudo systemctl restart ssh
    • Repeated the creation of ssh key for user2 on my local Ubuntu environment
    • Followed the same instructions as mentioned above and was able to login from my local Ubuntu environment successfully.

    Ubuntu VM:

    19840-z-ssh-6.jpg

    SSH login to VM with User 1:

    19799-z-ssh-7.jpg

    SSH login to VM with User 2:

    19941-z-ssh-8.jpg

    Plz note: In this case both Password and SSH auth will work.

    Hope the provided information is helpful. In case you have any further question please get back on this thread.

    Please 'Accept as answer' if the provided information is helpful, so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. facelessgreyhat 21 Reputation points
    2020-08-24T14:41:06.503+00:00

    @vipullag-MSFT - Thanks a lot Vikas for the help. Since I had setup my SSH from the portal by giving all the relevant info, I was having an impression that I need to create my 2nd user on my "Ubuntu Server" and generate Public/Private key pair and use them from a SSH client. Hence I was adding the public key under the authorized_keys file of the 2nd user and not appending to authorized_keys file of the first user (configured from the portal)

    So here is my understanding, correct if I am wrong.

    1. Azure is gonna create an user for SSH by default when I configure it from the portal.
    2. Any additional SSH user if I am gonna create, the public key needs to be added to the authorized_keys file of the user configured from the portal and not in the respective users created on my ubuntu server.

    If my above understanding is correct, here is my follow-up question:

    Why is it always that I need to append by public keys to the authorized_keys file for the user configured from the portal ? I can have 100s of users added in my ubuntu server and each of them will have .ssh directory where I can store the public keys.

    What is the architectural thought process behind this ?


  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.