REMOTE_USER=azureuser
REMOTE_HOST=40.112.140.45
KEYS_DIR=/root/.ssh/
for key in $KEYS_DIR*.pub; do
cat $key | ssh $REMOTE_USER@$REMOTE_HOST “mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys”
done
ssh $REMOTE_USER@$REMOTE_HOST “chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys”
I would suggest to first try it directly from CLI, instead of using a script.
I tried using cli it doesn’t work out share your insights
Can you share the complete question?
As per my understanding, the task is to copy public key of root user onto to another vm, so that you will be able to ssh with password.
did you test, if you were able to ssh after adding the public key?
Hi,
Please share the Azure level and task number, and I’ll check it and provide feedback.
The Nautilus DevOps team is working on setting up secure SSH access for their virtual machines in Azure. One of the requirements is to add the SSH public key of the root user from the Azure client host (landing host) to the devops-vm
Azure VM’s authorized_keys
file. This ensures secure and password-less SSH access to the VM.
Task Details:
-
VM Details:
- The VM is named
devops-vm
and is running in the East US
region.
- You need to add the root user’s SSH public key from the Azure client host to the
authorized_keys
file of the VM’s root user.
- The SSH public key of the root user on the Azure client host is located at
/root/.ssh/id_rsa.pub
.
-
Public Key Addition:
- Copy the public key located at
/root/.ssh/id_rsa.pub
on the Azure client host to the authorized_keys
file of the root user on devops-vm
.
- Ensure that the proper permissions for the
.ssh
folder and authorized_keys
file are set on the VM.
-
Verification:
- After adding the public key, make sure that you are able to SSH into the
devops-vm
VM from the Azure client host without needing a password.
Important Notes:
- Ensure that the VM is up and running before attempting to SSH.
- You may need to adjust the firewall or security group rules for the VM to allow SSH access.
**** for this they already deployed linux vm for this task and it has public key having in it and out task is copy public key from local to linux vm
Hi team , please share your insights
Your second screenshot says that you have edited the file /home/azureuser/.ssh/authorized_keys
at this location.
while adding the public key to the authorized_keys
file, you need to switch to root user.
You need to add the public key to the file /root/.ssh/authorized_keys
at this location and you might need to edit sshd_config
file if needed.
can you ping me on discord instead? my discord id: srikanth_47152
I was facing same issue. Solved it using the below mentioned approach -
-
Update the ssh-key for the azureuser. I used az cli.
→ az vm user update -g $rg_name -n nautilus-vm --username azureuser --ssh-key-value “$(cat /root/.ssh/id_rsa.pub | xargs)”
-
Log into the nautilus-vm using the ssh-key. before that you have to find the public ip of the vm.
→ ssh azureuser@public-ip
-
The nautilus-vm is a ubuntu machine that does not allow root login. So you have to enable the root login first.
→ sudo passwd -u root
-
empty the /root/.ssh/authorized_keys file and add the ssh public key. You can copy it from /home/azureuser/.ssh/authorized_keys. then exit from the server.
-
Walla, now you should be able to do → ssh root@nautilus-vm-public-ip
then submit your task.
I was facing same issue. Solved it using the below mentioned approach -
-
Update the ssh-key for the azureuser. I used az cli.
→ az vm user update -g $rg_name -n nautilus-vm --username azureuser --ssh-key-value “$(cat /root/.ssh/id_rsa.pub | xargs)”
-
Log into the nautilus-vm using the ssh-key. before that you have to find the public ip of the vm.
→ ssh azureuser@public-ip
-
The nautilus-vm is a ubuntu machine that does not allow root login. So you have to enable the root login first.
→ sudo passwd -u root
-
empty the /root/.ssh/authorized_keys file and add the ssh public key. You can copy it from /home/azureuser/.ssh/authorized_keys. then exit from the server.
-
Walla, now you should be able to do → ssh root@nautilus-vm-public-ip
@raymond.baoly , I think the question lacks clarity about the usernames to be used for the nautilus-vm. Please check if the same can be updated. Thanks in advance.
Hi @crazylinux
Am I missing something? I’m still not sure which course level and task number you’re working on. Could you please share those details so I can check it for you?
@raymond.baoly ,
hello buddy. It is Azure Level 1 task 12 SSH into an Azure Virtual Machine.
Hi @crazylinux,
I’m still not sure what improvement you’re referring to. If it’s about the question not being clear on which username to use for the nautilus-vm
, I noticed that it does mention using the root
user.
Hi @raymond.baoly
hope you’re doing well. Yes I agree that root user is mentioned in the question. But as I mentioned in the solution I used - I had to use the azureuser for logging into the VM and then enable root user’s login. My request is to mention the azureuser in the question that needs to be used. I hope I’m clear on my point now.
Hi @crazylinux,
It’s a bit confusing regarding the user access. It seems we need to SSH into the VM using the ‘azureuser’ account first, then update the SSH configuration to allow access as the root user. I’ll forward this to the team for review and consideration.
1 Like
Hi @crazylinux @Akhilreddy11
The task is updated, please try again.
1 Like