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