普通用户,使用密钥登陆阿里云服务器

本文是针对普通用户,root用户设置密钥登陆,须要在aliyun官网设置密钥对。ubuntu

因此在按照本文操做时,要确保:服务器

  1. 有一个普通用户
  2. 普通用户已经有了sudo操做权限。(redhat系列加入wheel组,ubuntu加入sudo组)

一、传送公钥到服务器

首先,容许密码登陆。在/etc/ssh/sshd_config中,修改。ssh

PasswordAuthentication yes

而后,经过rsync使用密码把公钥传送到服务器。rest

rsync -av /home/jo/.ssh/id_rsa.pub <用户名>@<地址>:/home/<用户名>/.ssh/

最后,把公钥复制到authorized_keyscode

cat id_rsa.pub >> authorized_keys

二、修改配置文件

保证ssh服务器配置文件(默认为/etc/ssh/sshd_config)容许公钥登陆,并禁止密码登陆。io

PubkeyAuthentication yes  
PasswordAuthentication no

别忘了重启sshd服务登录

sudo systemctl restart sshd

三、保证权限正确

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

而后就能够经过密钥登陆。配置

相关文章
相关标签/搜索