linux ssh秘钥登录 && 禁用密码登录

linux ssh秘钥登录 && 禁用密码登录


su root #切换到root用户
useradd yutao #添加用户
passwd yutao #设置密码,接下来按提示输入2遍密码

visudo  #给普通用户sudo权限
##找到 root    ALL=(ALL)       ALL 
##添加 yutao   ALL=(ALL)       ALL

su yutao #切换到新用户
cd ~
mkdir .ssh
chmod -R 700 .ssh
vim authorized_keys #添加客户端ssh公钥
chmod -R 600 authorized_keys

vim /etc/ssh/sshd_config
#修改 AuthorizedKeysFile .ssh/authorized_keys #公钥公钥认证文件
#修改 PubkeyAuthentication yes  #允许使用公钥登录
#修改 PasswordAuthentication no #禁止使用密码登录
#修改 ClientAliveInterval 60 #超时的时间(秒)
#修改 ClientAliveCountMax 10  #是指允许超时的次数

systemctl restart sshd # 重启sshd服务

Comments are closed.