Useful Commands/Security
Jump to navigation
Jump to search
| 情境 | 指令 |
|---|---|
| 從裡面間接出去 |
any -> localhost:8888 -> server:22 -> somewhere.com:80 ssh -NCfL *:8888:somewhere.com:80 server
|
| 讓外面間接進來 |
效果會因為 sshd_config 的 GatewayPorts 而有差異 [GatewayPorts no]: bind 127.0.0.1 (預設)
home-nas -> home-nas:60080 -> home-nas:22 -> office-pc:## -> 192.168.1.100:80
[GatewayPorts yes]: bind 0.0.0.0
Any -> home-nas:60080 -> home-nas:22 -> office-pc:## -> 192.168.1.100:80
在 office-pc 執行這指令 ssh -NCfR 60080:192.168.1.100:80 home-nas
如果 GatewayPorts no 可以在回家時加上正向穿隧進行兩段穿隧 ssh -NCfL 61180:localhost:60080 home-nas
如果搭配 autossh 會更好用 autossh -M 11119 -NCfR 60080:192.168.1.100:80 home-nas
|
| SOCKS Relay Proxy |
Any -> localhost:3128 -> server:22 -> *:* ssh -NCfD *:3128 server
|
| 顯示已開啟的 Tunnel |
ps ax | awk '/ssh \-NCf/ { print $0 }' # 看完整指令
ps ax | awk '/ssh \-NCf/ { print $1 }' # 看 pid
ps ax | awk '/ssh \-NCf/ { print $7 }' # 看 port
ps ax | grep 'ssh \-NCf'
|
| 產生 OpenSSH 金鑰 |
cd ~/.ssh
ssh-keygen -N '' -f ~/.ssh/palmce
mv palmce palmce.pem
scp palmce.pub user@hostname:~
|
| 以私鑰連線到伺服器的 Security Shell 服務 | ssh -i 私鑰 帳號@主機
|
| 產生 RSA 公私鑰 |
ssh-keygen # 單純產生公私鑰,會問檔名和密碼
ssh-keygen -f abc -N '' # 指定檔名產生公私鑰,無密碼
ssh-keygen -f abc -N '12345' # 指定檔名指定密碼產生公私鑰
|
| 讀取私鑰轉出公鑰 |
ssh-keygen -yf 私鑰 # 單純私鑰轉公鑰
ssh-keygen -yf 私鑰 > authorized_keys # 首次加入 ssh 授權清單
ssh-keygen -yf 私鑰 >> authorized_keys # 第N次加入 ssh 授權清單
|