Ordinary user, use the key to log in to Alibaba Cloud server

Posted May 27, 20201 min read

This article is for ordinary user, root user to set the key login, you need to set the key pair on the aliyun official website.

So when following this article, make sure:

  1. Have an ordinary user
  2. Ordinary users already have the sudo operation permission.(Redhat series joins wheel group, ubuntu joins sudo group)

1. Transfer the public key to the server

First, allow password login. In /etc/ssh/sshd_config, modify it.

PasswordAuthentication yes

Then, use rsync to transfer the public key to the server using a password.

rsync -av /home/jo/.ssh/id_rsa.pub <user name> @ <address>:/home/<user name> /. ssh /

Finally, copy the public key to authorized_keys.

cat id_rsa.pub >> authorized_keys

2. Modify the configuration file

Ensure that the ssh server configuration file(default is/etc/ssh/sshd \ _config) allows public key login and prohibits password login.

PubkeyAuthentication yes
PasswordAuthentication no

Don't forget to restart sshd service

sudo systemctl restart sshd

3. Make sure the permissions are correct

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized \ _keys

Then you can log in with the key.