Change the connection method to EC2 from public key authentication to password authentication
** Similar articles ** Learn sshd_config and authorized_keys (for Amazon Linux 2)
Make an SSH connection to the target EC2 and switch the user to ** root **.
Be sure to make a backup before changing the settings.
# cd /etc/ssh/
# pwd
/etc/ssh
# ls -l
total 608
...
-rw-r--r-- 1 root root 2276 Mar 15 12:25 ssh_config
-rw------- 1 root root 3977 Mar 15 12:04 sshd_config
...
# cp -p sshd_config sshd_config_yyyymmdd
# ls -l
total 608
...
-rw-r--r-- 1 root root 2276 Mar 15 12:25 ssh_config
-rw------- 1 root root 3977 Mar 15 12:04 sshd_config
-rw------- 1 root root 3977 Mar 15 12:04 sshd_config_yyyymmdd
...
We will change the settings of sshd_config. (Change before) #PubkeyAuthentication yes PasswordAuthentication no
(After change) PubkeyAuthentication no PasswordAuthentication yes
# vi sshd_config
# cat sshd_config | grep PubkeyAuthentication
#PubkeyAuthentication yes
PubkeyAuthentication no
# cat sshd_config | grep PasswordAuthentication
PasswordAuthentication yes
#PasswordAuthentication no
# systemctl restart sshd.service
Use the vi command to change the settings, and use cat + grep to confirm that the changes have been made without any problems. Then restart sshd.service with the systemctl command.
Use Teraterm to check if you can log in with password authentication. At that time, please keep the current connection.
Enter the IP address and press OK.
Enter your username and password and select ** Use Brain Password (L) ** to connect.
I was able to connect.
Now you can change to password authentication. I was able to do it, but password authentication is not so good, so let's restore it.
# cp -p sshd_config_yyyymmdd sshd_config
# systemctl restart sshd.service