Skip to content

Instantly share code, notes, and snippets.

@luodin007
Last active April 14, 2018 11:03
Show Gist options
  • Save luodin007/16dcc47c6242436a9809e6df634b93c1 to your computer and use it in GitHub Desktop.
Save luodin007/16dcc47c6242436a9809e6df634b93c1 to your computer and use it in GitHub Desktop.
高级 SSH 速查表 #ssh

所有人都知道 SSH 是一种远程登录工具,然而它也有许多其他用途。

创建一个 SOCKS 代理来浏览网页(也就是翻墙啦):

ssh -D <port> <remote_host>

设置 localhost: 作为你浏览器的代理

连接一个堡垒机后的 Windows RDP 主机:

ssh -L <port>:<target_host>:3389 <bastion_server>

让你的 RDP 客户端连接到 localhost:

在不使用 VNC 端口的情况下,连接远程 VNC 主机:

ssh -L 5901:localhost:5901 <remote_host>

让你的 VNC 客户端连接到 localhost:5901。按照这个思路,你可以映射任意端口:LDAP (389)、631 (CUPS)、8080 (替代的 HTTP),等等

产生一个新的 SSH 密钥对:

ssh-keygen

更新密钥对的密码:

ssh-keygen -p

把公钥复制到远程主机上:

ssh-copy-id -i <identity file> <remote_host>

SSH 有一堆命令行选项,但是如果有一些是你经常使用的,你可以为它们在 SSH 配置文件 (${HOME}/.ssh/config) 里创建一个入口。比如: host myhouse User itsme
HostName http://house.example.com

那么你就可以输入 ssh myhouse 来代替 ssh itsme@house.example.com

以下是常用的命令行选项和他们的配置文件写法。一些是常用的简化写法。请查看 ssh(1) 和 ssh_config(5) 的手册页来获取详尽信息。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment