#生成秘钥

ssh-keygen -t rsa -b 4096

#~/.ssh目录
#公钥写入authorized_keys

cd .ssh
cat id_rsa.pub >> authorized_keys

#下载私钥id_rsa
#删除id_rsa & id_rsa.pub

#修改目录权限

chmod ~/.ssh/ 700
chmod .ssh/authorized_keys 644

#编辑sshd_config

vim /etc/ssh/sshd_config
#跳过检查文件所有权
StrictModes no
#开启秘钥登陆
PubkeyAuthentication yes
#秘钥存放位置
AuthorizedKeysFile	.ssh/authorized_keys
#关闭密码登陆
PasswordAuthentication no

#重启sshd

systemctl restart sshd.service

#自启sshd

systemctl enable sshd.service