Skip to content

SSH常用命令

序号高级用法命令示例
1端口转发ssh -L [local port]:[remote host]:[remote port] [username]@[remote host]
2执行远程命令ssh [username]@[remote host] '[command]'
3多重跳转ssh -J [jump host 1],[jump host 2],... [username]@[remote host]
4执行本地命令ssh [username]@[remote host] 'bash -s' < [local script]'
5使用SSH作为SOCKS代理ssh -D [local port] [username]@[remote host]
6复制文件scp [local file] [username]@[remote host]:[remote path]
7传输文件夹scp -r [local folder] [username]@[remote host]:[remote path]
8使用SSH密钥ssh -i [private key file] [username]@[remote host]
9远程桌面连接ssh -X [username]@[remote host]
10使用SSH配置文件ssh -F [config file] [username]@[remote host]
11使用SSH管道ssh [username]@[remote host] 'command1 | command2 | command3'
12SSH登录后自动执行命令ssh -t [username]@[remote host] '[command];bash'
13配置多个SSH密钥ssh -i [private key file 1] [username]@[remote host 1]
ssh -i [private key file 2] [username]@[remote host 2]
14使用SSH连接串联多个主机ssh [username]@[host 1] ssh [username]@[host 2] ssh [username]@[host 3]
15使用SSH连接到串口ssh -t [username]@[remote host] 'sudo screen /dev/ttyS0 115200'
16使用SSH连接到远程MySQL服务器ssh -L [local port]:[remote MySQL host]:[remote MySQL port] [username]@[remote host]
17使用SSH连接到远程PostgreSQL服务器ssh -L [local port]:[remote PostgreSQL host]:[remote PostgreSQL port] [username]@[remote host]
18使用SSH连接到远程VNC服务器ssh -L [local port]:[remote VNC host]:[remote VNC port] [username]@[remote host]
19使用SSH连接到远程RDP服务器ssh -L [local port]:[remote RDP host]:[remote RDP port] [username]@[remote host]
20使用SSH连接到远程FTP服务器ssh -L [local port]:[remote FTP host]:[remote FTP port] [username]@[remote host]

Released under the MIT License.