Cannot Connect via SSH to Ubuntu 22.04 Machines With Private Key
Description
Connecting to an Ubuntu 22.04 VM with a private key using the SSH direct access link may fail.
Solution
To resolve this issue:
-
Login to Ubuntu 22.04 machine.
-
Edit
/etc/ssh/sshd_config
. -
Add the following line to the end of the config file:
PubkeyAcceptedKeyTypes +ssh-rsa
-
Restart ssh server:
systemctl restart ssh
Or run this command:
sudo echo -e "PubkeyAcceptedKeyTypes +ssh-rsa\nHostKeyAlgorithms +ssh-rsa" >> /etc/ssh/sshd_config&&systemctl restart ssh
To deploy an Ubuntu-22.04 AWS EC2 App:
-
Create the script with the below content and place it in an S3 bucket or make it accessible from the deployed App's VM.
#!/bin/bash
sudo echo -e "PubkeyAcceptedKeyTypes +ssh-rsa\nHostKeyAlgorithms +ssh-rsa" >> /etc/ssh/sshd_config&&systemctl restart ssh -
In the App's Deployment Paths page, specify a link to the script in the USER DATA URL attribute.