ssh-remote

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SSH Remote Access

SSH远程访问

Overview

概述

SSH (Secure Shell) provides encrypted remote access, file transfer, and tunneling over untrusted networks. OpenSSH is the standard implementation on Linux, macOS, and Windows (via built-in client). The client configuration lives at
~/.ssh/config
and supports per-host settings, identity management, and connection reuse.
When to use: Remote server management, secure file transfers, port forwarding, jump host traversal, automated deployments, SOCKS proxying.
When NOT to use: High-throughput bulk data transfer across WANs (use Globus or similar), GUI-heavy remote desktop (use VNC/RDP), container orchestration (use kubectl/docker CLI).
SSH(Secure Shell)可在不可信网络上提供加密的远程访问、文件传输和隧道功能。OpenSSH是Linux、macOS和Windows(通过内置客户端)上的标准实现。客户端配置位于
~/.ssh/config
,支持按主机设置、身份管理和连接复用。
适用场景: 远程服务器管理、安全文件传输、端口转发、跳转主机遍历、自动化部署、SOCKS代理。
不适用场景: 跨广域网的高吞吐量批量数据传输(使用Globus或类似工具)、GUI密集型远程桌面(使用VNC/RDP)、容器编排(使用kubectl/docker CLI)。

Quick Reference

快速参考

PatternCommand / DirectiveKey Points
Basic connect
ssh user@host
Add
-p PORT
for non-default port
Identity file
ssh -i ~/.ssh/key user@host
Specify private key explicitly
Remote command
ssh user@host "command"
Add
-t
for interactive commands
SSH config alias
Host myserver
block in
~/.ssh/config
Simplifies repeated connections
File copy (rsync)
rsync -avzP src user@host:dest
Preferred over scp for all transfers
File copy (scp)
scp file user@host:path
Legacy protocol; uses SFTP internally
Local tunnel
ssh -L local:remote_host:remote_port
Access remote services locally
Remote tunnel
ssh -R remote:localhost:local_port
Expose local services to remote
SOCKS proxy
ssh -D 1080 user@host
Dynamic port forwarding
Jump host
ssh -J jump user@target
ProxyJump, available since OpenSSH 7.3
Key generation
ssh-keygen -t ed25519
Ed25519 recommended for all new keys
FIDO2 key
ssh-keygen -t ed25519-sk
Hardware-backed, requires OpenSSH 8.2+
Agent
ssh-add ~/.ssh/key
Cache key passphrase for session
Multiplexing
ControlMaster auto
in config
Reuse TCP connections across sessions
Debug
ssh -v user@host
Up to
-vvv
for maximum verbosity
模式命令/指令核心要点
基础连接
ssh user@host
非默认端口需添加
-p PORT
参数
身份文件
ssh -i ~/.ssh/key user@host
显式指定私钥
远程命令
ssh user@host "command"
交互式命令需添加
-t
参数
SSH配置别名
~/.ssh/config
中的
Host myserver
简化重复连接
文件复制(rsync)
rsync -avzP src user@host:dest
所有传输场景优先使用,优于scp
文件复制(scp)
scp file user@host:path
旧版协议;内部使用SFTP
本地隧道
ssh -L local:remote_host:remote_port
本地访问远程服务
远程隧道
ssh -R remote:localhost:local_port
向远程暴露本地服务
SOCKS代理
ssh -D 1080 user@host
动态端口转发
跳转主机
ssh -J jump user@target
ProxyJump,OpenSSH 7.3及以上版本支持
密钥生成
ssh-keygen -t ed25519
所有新密钥推荐使用Ed25519
FIDO2密钥
ssh-keygen -t ed25519-sk
硬件加密,需OpenSSH 8.2+版本支持
代理
ssh-add ~/.ssh/key
会话期间缓存密钥密码
多路复用配置中添加
ControlMaster auto
跨会话复用TCP连接
调试
ssh -v user@host
最多可使用
-vvv
获取最大详细程度日志

Key Type Recommendations

密钥类型推荐

AlgorithmRecommendationNotes
Ed25519Default for all new keys256-bit, fast, secure, supported on OpenSSH 6.5+
Ed25519-SK (FIDO2)Strongest option with hardware keyRequires physical security key, OpenSSH 8.2+
RSA 4096Legacy compatibility onlyUse only when Ed25519 is unsupported by the remote system
ECDSAAvoidImplementation concerns; prefer Ed25519
算法推荐方案说明
Ed25519所有新密钥的默认选择256位,快速、安全,OpenSSH 6.5+版本支持
Ed25519-SK(FIDO2)搭配硬件密钥的最强选项需要物理安全密钥,OpenSSH 8.2+版本支持
RSA 4096仅用于旧版兼容性场景仅当远程系统不支持Ed25519时使用
ECDSA避免使用存在实现问题;优先选择Ed25519

File Transfer Decision Guide

文件传输决策指南

ScenarioToolWhy
Recurring syncs or large directories
rsync -avzP
Delta sync, compression, resume, progress
Quick one-off file copy
scp
or
rsync
scp is simpler; rsync is more capable
Interactive file browsing
sftp
Tab completion, directory navigation
High-bandwidth WAN transfersSpecialized tools (Globus)SSH buffer limits reduce WAN throughput
场景工具原因
定期同步或大型目录传输
rsync -avzP
增量同步、压缩、断点续传、进度显示
快速单次文件复制
scp
rsync
scp更简单;rsync功能更强大
交互式文件浏览
sftp
支持Tab补全、目录导航
高带宽广域网传输专用工具(如Globus)SSH缓冲区限制会降低广域网吞吐量

Common Mistakes

常见错误

MistakeCorrect Pattern
Using RSA keys for new setupsGenerate Ed25519 keys -- faster, smaller, and equally secure
Using
scp
for large or recurring transfers
Use
rsync -avzP
for compression, progress, and resumable delta sync
Typing passphrase repeatedly during sessionsUse
ssh-agent
and
ssh-add
to cache keys for the session
Connecting through multiple hops with nested SSHUse
-J
(ProxyJump) for clean bastion/jump host traversal
Running interactive commands without
-t
flag
Use
ssh -t user@host "htop"
to allocate a pseudo-terminal
Using
ForwardAgent yes
through untrusted hosts
Use ProxyJump instead -- agent forwarding exposes keys to compromised hosts
Setting
ControlPath
without
%h
,
%p
,
%r
Include all three tokens to ensure unique sockets per connection
Disabling host key checking globallyOnly use
StrictHostKeyChecking no
in trusted, ephemeral environments
Not using
IdentitiesOnly yes
Prevents offering every loaded key to every server
错误正确做法
新部署使用RSA密钥生成Ed25519密钥——更快、体积更小且安全性相当
大型或定期传输使用
scp
使用
rsync -avzP
,支持压缩、进度显示和可恢复的增量同步
会话中重复输入密码使用
ssh-agent
ssh-add
在会话期间缓存密钥
通过嵌套SSH连接多跳主机使用
-J
(ProxyJump)实现清晰的堡垒机/跳转主机遍历
运行交互式命令时不加
-t
标志
使用
ssh -t user@host "htop"
分配伪终端
在不可信主机上启用
ForwardAgent yes
改用ProxyJump——代理转发会将密钥暴露给已被攻陷的主机
设置
ControlPath
时未包含
%h
%p
%r
包含这三个令牌以确保每个连接的套接字唯一
全局禁用主机密钥检查仅在可信的临时环境中使用
StrictHostKeyChecking no
未使用
IdentitiesOnly yes
避免向每个服务器提供所有已加载的密钥

Security Checklist

安全检查清单

  • Generate Ed25519 keys with strong passphrases
  • Set
    PasswordAuthentication no
    on servers
  • Set
    PermitRootLogin prohibit-password
    or
    no
  • Use
    IdentitiesOnly yes
    in client config
  • Restrict keys with
    command=
    and
    from=
    in
    authorized_keys
  • Use FIDO2 hardware keys (
    ed25519-sk
    ) for high-security environments
  • Install
    fail2ban
    on servers to block brute-force attempts
  • Consider SSH certificate authentication for fleet management
  • 使用强密码生成Ed25519密钥
  • 在服务器上设置
    PasswordAuthentication no
  • 设置
    PermitRootLogin prohibit-password
    no
  • 在客户端配置中使用
    IdentitiesOnly yes
  • authorized_keys
    中通过
    command=
    from=
    限制密钥使用
  • 高安全环境使用FIDO2硬件密钥(
    ed25519-sk
  • 在服务器上安装
    fail2ban
    以阻止暴力破解尝试
  • 考虑使用SSH证书认证进行集群管理

Delegation

任务分工

  • Server inventory discovery and connection testing: Use
    Explore
    agent
  • Multi-host deployment or bulk file transfers: Use
    Task
    agent
  • Network architecture and bastion host planning: Use
    Plan
    agent
  • 服务器清单发现与连接测试:使用
    Explore
    agent
  • 多主机部署或批量文件传输:使用
    Task
    agent
  • 网络架构与堡垒机规划:使用
    Plan
    agent

References

参考资料

  • Connections, SSH config, and remote commands
  • File transfers with rsync and scp
  • Port forwarding, SOCKS proxy, and jump hosts
  • Key management, FIDO2 keys, agent, and security hardening
  • 连接、SSH配置与远程命令
  • 基于rsync和scp的文件传输
  • 端口转发、SOCKS代理与跳转主机
  • 密钥管理、FIDO2密钥、代理与安全加固