mac开启sshd服务

mac 无法ssh localhost,错误提示:bash: /usr/local/bin/ssh_session: Permission denied


1.编辑/etc/sshd_config文件,注释掉

#ForceCommand /usr/local/bin/ssh_session

(第1点在配置文件中没找到,执行下面的几步后sshd服务就可以启动了)


2.启动sshd服务:

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


3.停止sshd服务:

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


4查看是否启动:

sudo launchctl list | grep ssh


如果看到下面的输出表示成功启动了:

--------------

- 0 com.openssh.sshd


5.最后ssh localhost 成功


转载于:https://my.oschina.net/ylchou/blog/526728

<think>我们正在解决用户的问题:如何在Ubuntu上开启VSCode的SSH服务,以便进行远程开发。 注意:用户提到的VSCode SSH服务实际上是指配置Ubuntu系统的SSH服务,使得VSCode可以通过Remote-SSH插件进行连接。 步骤: 1. 在Ubuntu上安装并启动SSH服务器(openssh-server)。 2. 配置SSH服务(如允许root登录、密钥认证等,可选)。 3. 在VSCode中安装Remote-SSH插件并连接。 根据引用[1]:我们需要确保SSH服务已经在Ubuntu上运行。 具体步骤:</think>### 在Ubuntu上配置VSCode的SSH远程开发环境 以下是完整配置步骤,让VSCode通过SSH连接Ubuntu进行远程开发: #### 1. 在Ubuntu上安装并启动SSH服务 ```bash # 安装OpenSSH服务器 sudo apt update && sudo apt install openssh-server -y # 启动SSH服务 sudo systemctl start ssh # 设置开机自启 sudo systemctl enable ssh # 验证服务状态(应显示"active (running)") sudo systemctl status ssh ``` > 确保防火墙允许SSH端口(默认22)[^1]: > ```bash > sudo ufw allow 22/tcp > ``` #### 2. 配置VSCode客户端 1. 在Windows/Mac安装VSCode 2. 安装官方扩展:**Remote - SSH** ![Remote-SSH扩展](https://code.visualstudio.com/assets/docs/remote/ssh/ssh-extension.png) 3. 按`Ctrl+Shift+P`打开命令面板,选择**Remote-SSH: Connect to Host** #### 3. 建立SSH连接 ```bash ssh username@ubuntu_ip ``` > 首次连接需接受主机密钥: > ``` > The authenticity of host '192.168.1.100 (192.168.1.100)' can't be established. > ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxx. > Are you sure you want to continue connecting (yes/no/[fingerprint])? > ``` #### 4. 密钥认证配置(推荐) ```bash # 在本地生成密钥对 ssh-keygen -t ed25519 # 将公钥复制到Ubuntu ssh-copy-id username@ubuntu_ip # 验证免密登录 ssh username@ubuntu_ip ``` > 若密钥认证失败[^4]: > 1. 检查Ubuntu上`~/.ssh/authorized_keys`文件权限应为`600` > 2. 确认`/etc/ssh/sshd_config`包含: > ```conf > PubkeyAuthentication yes > AuthorizedKeysFile .ssh/authorized_keys > ``` #### 5. 在VSCode中操作远程文件 连接成功后: - 左侧资源管理器可访问远程文件系统 - 终端自动连接到Ubuntu shell - 支持安装远程扩展(如Python、Docker等) ![VSCode远程开发界面](https://code.visualstudio.com/assets/docs/remote/ssh/remote-ssh-status-bar.png) #### 6. 高级配置(可选) **修改SSH端口**(编辑`/etc/ssh/sshd_config`): ```conf Port 2222 # 改为自定义端口 PermitRootLogin prohibit-password PasswordAuthentication no # 禁用密码登录增强安全 ``` 重启服务生效: ```bash sudo systemctl restart ssh ``` **通过代理连接**(如需要)[^3]: ```bash # 在VSCode的SSH配置(~/.ssh/config)添加: Host ubuntu-proxy HostName ubuntu_ip User username ProxyCommand nc -X 5 -x proxy_ip:port %h %p ``` ### 验证远程开发 1. 在VSCode中打开远程终端 2. 创建测试文件: ```bash echo "Hello Remote Dev!" > test.txt ``` 3. 安装Python扩展,尝试运行简单脚本
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值