- 新建一个ssh用户和组
groupadd -g 1009 tomcat
useradd -u 1009 -g 1009 tomcat
- 设置新建用户能使用sudo
chmod u+w /etc/sudoers
vim /etc/sudoers
##加入文件### tomcat ALL=(ALL) NOPASSWD: ALL
chmod u-w /etc/sudoers
- 进入新用户
su tomcat
- 配置ssh密钥:
ssh-keygen -t rsa
进入文件夹,将id_rsa.pub命名为authorized_keys。
cd .ssh
mv id_rsa.pub authorized_keys
chmod 600 authorized_keys
用你熟悉的方法将私钥拉id_rsa到本地。
- 修改SSH配置
sudo vim /etc/ssh/sshd_config
###修改一下内容RSAAuthentication yes #PubkeyAuthentication yes #AuthorizedKeysFile /home/tomcat/.ssh/authorized_keys #路径ChallengeResponseAuthentication noPasswordAuthentication no #密码登录不允许UsePAM noPermitRootLogin no #不允许root远程登录
- 重启SSH服务
sudo systemctl restart sshd.service
原创文章转载请注明:转载自:linux配置密钥登录
发表评论
沙发空缺中,还不快抢~