You've already forked www.colben.cn
update
This commit is contained in:
61
content/post/ssh.md
Normal file
61
content/post/ssh.md
Normal file
@@ -0,0 +1,61 @@
|
||||
---
|
||||
title: "ssh 命令"
|
||||
date: 2019-10-29T21:10:48+08:00
|
||||
lastmod: 2019-10-29T21:10:48+08:00
|
||||
keywords: []
|
||||
tags: ["ssh", "隧道", "转发"]
|
||||
categories: ["shell"]
|
||||
---
|
||||
|
||||
# sshd 常规设置
|
||||
- 禁用 root 远程登陆
|
||||
```
|
||||
PermitRootLogin no
|
||||
```
|
||||
- 只允许私钥登陆
|
||||
```
|
||||
PubkeyAuthentication yes
|
||||
PasswordAuthentication no
|
||||
```
|
||||
- 开启端口转发功能
|
||||
```
|
||||
AllowTcpForwarding yes
|
||||
GatewayPorts yes
|
||||
X11Forwarding yes
|
||||
TCPKeepAlive yes
|
||||
ClientAliveInterval 60
|
||||
ClientAliveCountMax 3
|
||||
```
|
||||
|
||||
# ssh 参数
|
||||
- -f 后台运行
|
||||
- -N 仅作端口转发,不执行任何命令
|
||||
- -g 绑定端口到全部网卡
|
||||
|
||||
# 本地定向转发
|
||||
- ssh-client 不可达 remote-host, ssh-server 可达 remote-host, ssh 隧道映射 ssh-client 指定端口到 remote-host 指定端口
|
||||
- 在 ssh-client 执行
|
||||
```bash
|
||||
ssh -f -N -g \
|
||||
-L [<ssh-client-ip>:]<port on ssh-client>:<remote-host>:<port on remote-host> \
|
||||
username@<ssh-server>
|
||||
```
|
||||
|
||||
# 远程定向转发
|
||||
- ssh-client 可达 remote-host, ssh-server 不可达 remote-host, ssh 隧道映射 ssh-server 指定端口到 remote-host 指定端口
|
||||
- 在 ssh-client 执行
|
||||
```bash
|
||||
ssh -f -N -g \
|
||||
-R [<ssh-server-ip>:]<port on ssh-server>:<remote-host>:<port on remote-host> \
|
||||
username@<ssh-server>
|
||||
```
|
||||
|
||||
# 动态转发
|
||||
- SOCKS5 代理
|
||||
- 在 ssh-client 执行
|
||||
```bash
|
||||
ssh -f -N -g \
|
||||
-D <port on ssh-client> \
|
||||
username@<ssh-server>
|
||||
```
|
||||
|
Reference in New Issue
Block a user