The default user of Tencent Cloud Ubuntu 18.04 is ubuntu, while other default users such as CentOS Debian are root.
The following is how to enable root login on Ubuntu 18.04:
//Login as user ubuntu
sudo -i
vim /etc/ssh/sshd_config
//Move the cursor to the PermitRootLogin line, click the i key to switch to editable,//If you do not need to use a password to log in to root (recommended), only use the key to log in, then remove#Can//After modification, click the esc key to exit the editable state, enter:wq Enter, save and exit//Many online tutorials are the above steps, but after the modification, you will find that you cannot log in with the key. The key is the following step
cat /home/ubuntu/.ssh/authorized_keys >>/root/.ssh/authorized_keys
//will/home/Copy the ubuntu user's credentials to the ubuntu directory/root/.ssh/authorized_keys, everything is normal at this time//Finished, just these three commands
PermitRootLogin default value prohibit-password is to prohibit password login (but you can log in with a key). If you need a password to log in, change to yes
I first checked vim ~/.ssh/authorized_keys and saw that there was content. I thought there was content in /root/.ssh/authorized_keys. In fact, the ~ symbol represents the /home/ubuntu directory, which is the user of the current user ubuntu. table of Contents
I got the correct answer after reading this: https://github.com/lmk123/blog/issues/64
After logging in to the host again, you can delete the ubuntu user:
deluser ubuntu --remove-home
Recommended Posts