macOS(BSD system) 禁用 ssh 密码登录(转)

As any BSD system you should toggle off some options in your sshd_:
 
 
sudo vim /etc/ssh/sshd_config
 
 
UsePam yes # it will not be used
 
ChallengeResponseAuthentication no
 
PasswordAuthentication no
 
kbdInteractiveAuthentication no
 
# 直接在sshd_config的最后添加这4行既可
 
sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
 
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist 
 
 
来源   https://wiki.butou.ma/mac/macos-jin-yong-ssh-mi-ma-deng-lu
 

在Mac上打开sshd访问权限

  • 勾选 Apple menu > System Preferences > Sharing > Remote Login (启动台 ->系统偏好设置->共享->远程登录)
  • 选择任何人

修改 sshd 配置

在/etc/ssh/sshd_config文件中只需打开下面几项:

  • AuthorizedKeysFile .ssh/authorized_keys 指定被授权的用户的rsa 加密key存放的位置。
  • UsePAM 使用 PAM 进行权限管理。
  • AcceptEnv LANG LC_* 指明本地位置信息。
  • Subsystem sftp /usr/libexec/sftp-server 默认协议。

在客户端生成 ssh rsa key

  • 执行 ssh-genkey -t rsa 命令,然后要求输入的地方一直回车。
  • 打开~/.ssh/id-rsa.pub文件,拷贝里面的内容。

启动 sshd 服务

sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

停止 sshd 服务

sudo launchctl unload -w /System/Library/LaunchDaemons/ssh.plist

查看sshd服务是否启动

sudo launchctl list | grep ssh

posted @ 2024-03-10 22:15  就是想学习  阅读(34)  评论(0编辑  收藏  举报