ramlife

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

创建许可文件

先使用 ssh-keygen -t rsa 来生成 .ssh 目录,然后把生成的密钥下载到本地,并在 .ssh 下创建一个空文件 authorized_keys

录入公钥

使用 vim 打开 authorized_keys,并把允许登录电脑生成的公钥复制进去,一行就是一个许可的公钥。

登录

win

在 ssh 登录客户端,配置为使用私钥,然后选择本地的私钥文件,之后就可以点击直接登录了。

禁止密码登录

修改 /etc/ssh/sshd_config,找到下面这几行,对应修改如下即可:

PubkeyAuthentication yes
PasswordAuthentication no

重启 sshd

群晖

synoservicectl --restart sshd

linux

service sshd restart #centos系统
service ssh restart #ubuntu系统
/etc/init.d/ssh restart #debian系统

验证配置结果

重新使用密码方式进行登录,返回 No supported authentication methods available (server sent: publickey),说明密码登录成功关闭。

参考:

ssh禁止密码登录
https://www.cnblogs.com/tl542475736/p/7814097.html

关闭ssh密码登录
https://blog.csdn.net/weixin_34186931/article/details/86048201

linux ssh使用秘钥登录并禁用密码登录
https://blog.csdn.net/qq_32506245/article/details/81355497

关掉 ssh 的密码登陆
https://www.jianshu.com/p/cc612e53ac75

SSH登录方式及如何防止SSH端口被扫
https://www.cnblogs.com/programmerwang/p/15922460.html

Synology 群晖 ssh 命令清单大全(附命令解释说明)
https://zhuanlan.zhihu.com/p/459751737

posted on 2023-01-30 21:07  ramlife  阅读(2089)  评论(0编辑  收藏  举报