ssh user@host
ssh -p 2222 user@host
ssh -i ~/.ssh/id_ed25519 user@host
ssh -v user@host
ssh -J bastion user@internal
ssh-keygen -t ed25519 -C 'me@example.com'
ssh-copy-id user@host
ssh-add ~/.ssh/id_ed25519
ssh -L 8080:localhost:80 user@host
ssh -R 9000:localhost:3000 user@host
ssh -D 1080 user@host
scp file user@host:/tmp/
sftp user@host
~/.ssh/config:
Host prod
HostName 10.0.0.10
User deploy
Port 22
IdentityFile ~/.ssh/id_ed25519
ProxyJump bastion
| 目的 | 命令 |
|---|---|
| 复用连接 | ControlMaster auto + ControlPath |
| 保持连接 | ServerAliveInterval 30 |
| 本地转发 | ssh -L 本地:目标:端口 host |
| 远程转发 | ssh -R 远端:目标:端口 host |
| 动态代理 | ssh -D 1080 host |
| 查看已知主机 | ssh-keygen -F host |
| 移除旧主机键 | ssh-keygen -R host |
| 复制公钥 | ssh-copy-id -i key.pub host |
.ssh 权限应为 700,authorized_keys 和私钥为 600。authorized_keys 移除对应公钥。known_hosts 变更可能是重装系统,也可能是中间人;先确认再删除。-L 的绑定地址和 GatewayPorts 决定谁能访问转发端口。ProxyJump 需要跳板机允许转发;老版本用 ProxyCommand。~/.ssh/config > /etc/ssh/ssh_config。ssh — 完整命令页ssh-keygen — 密钥管理sshd — 服务端配置