how enable and use ssh key for login for a non-root / non-sudo user in azure linux VM

Shabeer 1 Reputation point
2022-12-06T05:01:25.273+00:00

i have created ssh public and private key using ssh-keyggen command. And when i am updating it from the azure webpage (in Rest password section of VM), it is getting sudo priviledges. I need to use ssh key or ppk for non root user login

Azure VMware Solution
Azure VMware Solution
An Azure service that runs native VMware workloads on Azure.
360 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. vipullag-MSFT 26,391 Reputation points
    2022-12-06T05:59:18.557+00:00

    @Shabeer

    Welcome to Microsoft Q&A Platform, thanks for posting your query here.

    As you already have created ssh key pair using ssh-keyggen command, login to the Linux VM as root user (azureuser).

    Else you can check this document on how to create a ssh key pairs.

    Once logged into Azure VM, create a new user as shown in below screenshot using useradd command:

    sudo useradd username  
    

    267654-image.png

    In Azure portal, select the VM and go to Reset Password option and give the newly created user name and public key of the new user that you have already created and click on update to update the SSH key login for the new user.

    267642-image.png

    Once the SSH login is updated for new user, you can SSH into the VM with newuser@publicip by providing the private key through putty or directly depending on how you are accessing the VM.

    You can verify the login user once as shown below:
    267643-image.png

    Also, you can run below command to list down the root/super users, this is to make sure that you ask of non-root/non-sudo is verified.
    This command list down the privileged users only. The newly created user will not be in the list as it is a non-root user.

    grep '^sudo:.*$' /etc/group | cut -d: -f4  
    

    267644-image.png

    Hope this helps.
    If you need further help on this, tag me in a comment.
    If the suggested response helped you resolve your issue, please 'Accept as answer', so that it can help others in the community looking for help on similar topics.

    0 comments No comments

  2. sam john 0 Reputation points
    2024-04-08T22:33:47.6433333+00:00

    You have to use PuTTYgen to generate SSH key (public and private key).

    To know the process of generating key click here.

    0 comments No comments

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.