在 macOS 上用 ssh 登录远程电脑

用系统自带的 ssh 客户端安全连接另一台 Mac、Linux 服务器或家用主机。

macOSmacOS网络终端命令行中风险
运行 ssh admin@192.168.1.20(非默认端口加 -p 2222),首次连接确认主机指纹后输入对方密码即可登录。

01命令

命令
$ ssh admin@192.168.1.20

02作用说明

macOS 自带 OpenSSH 客户端,无需安装:ssh user@host 会建立加密的远程 Shell,之后每条命令都在远端执行。目标写法 user@hostname 支持 IP、域名或 ~/.ssh/config 里的别名,-p 指定自定义端口。若想让自己也被远程访问,需在目标 Mac 的系统设置 > 通用 > 共享中打开“远程登录”。配合 ssh-keygen 和 ssh-add 还可免密登录。

03风险

风险中风险
使用条件Target host must have Remote Login / sshd running; first connection asks to confirm the host key.
!注意: 请只连接你有权使用的机器;每次确认的主机指纹都会记录在 ~/.ssh/known_hosts。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • ssh(1) man page
    Xcode Man Pages (keith.github.io) · technical · 2026-09-17
    依据: Man page for ssh: 'ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface] [-b bind_address] [-c cipher_spec] … [-p port] destination [command]' with destination in user@hostname form.
  • ssh(1) - OpenSSH remote login client
    ManPagez · technical · 2026-09-17
    依据: Mirrors the ssh man page: ssh (SSH client) is a program for logging into a remote machine and executing commands, connecting as user@hostname.

最后验证: 2026-09-19 · 分类: 网络

06相关方案