Skip to content

OpenSSH

Port of OpenBSD's free SSH release https://www.openssh.com/

Setup a SOCKS5 proxy

Start a SOCKS5 proxy: ssh -C -D 1080 -N -q -A -p 22 my-user@my-host

Test proxy server via cURL: curl --socks5 localhost:1080 httpbin.org/ip

Setup a SOCKS5 proxy with auto-restart

autossh — monitor and restart ssh sessions

Install the autossh util

shell
# Ubuntu
apt install autossh

# macOS
brew install autossh

Start a SOCKS5 proxy: autossh -M20000 -f -C -D 1080 -N -q -A -p 22 my-user@my-host

Notes on options

-M specifies the base monitoring port to use.
-f causes autossh to drop to the background before running ssh.

-C Requests compression of all data (including stdin, stdout, stderr, and data for forwarded X11, TCP and Unix-domain connections).
-D [bind_address:]port Specifies a local "dynamic" application-level port forwarding.
-N Do not execute a remote command.
-q Quiet mode. Causes most warning and diagnostic messages to be suppressed.
-A Enables forwarding of connections from an authentication agent such as ssh-agent(1).
-p Port to connect to on the remote host.

Usages

login with password ssh -o PasswordAuthentication=yes -o PubkeyAuthentication=no myuser@myip

FAQs

we did not send a packet, disable method

在 sshd 配置 /etc/ssh/sshd_config 添加了 PubkeyAuthentication yes 选项允许 通过公钥登录后,依然显示

shell
ssh -vv localhost

...
we did not send a packet, disable method
...

有可能是目录权限不对导致。

解决:

shell
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Released under the CC-BY-NC-4.0