Some SSH Commands

Some SSH Commands, proxy and tunnel.

SSH is the de facto standard for remote terminals these days. However, it can do other things besides normal terminal use, such as tunneling which is useful in some situations.

Pubkey Authentication

Using pubkey authentication with SSH can save some time typing passwords.

On your local computer, use ssh-keygen to create SSH key pairs, which usually come with Windows, Linux, and Mac. Several key types are supported, and I prefer the ed25519 for its short length.

1
2
3
4
ssh-keygen -t rsa -b 4096
ssh-keygen -t dsa 
ssh-keygen -t ecdsa -b 521
ssh-keygen -t ed25519 -C Comment

By default, the key-pair will be saved to ~/.ssh/id_ed25519 and ~/.ssh/id_ed25519.pub, the name will change base on key type. The path can also be set by using -f ~/key option. The key file is in PEM format and can be convert to PPK format using PuTTYgen.

Add private key to ssh-agent to use it for login.

1
ssh-agent add ~/.ssh/id_ed25519

On the remote computer, write the pubkey contents to ~/.ssh/authorized_keys and the sshd will use it for login, multiple keys can be added.

Tunneling

Share a port to remote machine

1
ssh user@remote-host -R 10000:localhost:9090

localhost:9090 is the local port to share, it will bind to remote port 10000. If the remote port is not default 22, eg. 10022, use -p 10022 option.

This can be used to share a http proxy to remote machine to enable Internet access.

Bind a remote port to local

1
ssh user@remote-host -L 7860:localhost:7860

localhost:7860 is the remote port to share, it will bind to local port 7860.

This can be used to run Gradio in a remote GPU cluster and share the page to local machine.

Use remote as a Internet proxy

1
ssh -D localhost:9090 user@remote-host

This will open a SOCKS5 proxy port at local machine to internet access via remote-host.

ProxyJump

1
ssh -J user1@remote-host1 user@remote-target

-R, -L and -p options can also be used, but is only effective to the remote-target. If non default port and multiple proxy is needed, the format is:

1
ssh -J user1@remote-host1:10022,user2@remote-host2:10023 user@remote-target -p 10024

This function connects with a path like remote-host1->remote-host2->remote-target, suitable for use if direct connection is not possible due to firewall.

Licensed under CC BY-NC-SA 4.0
Last updated on 05 Jun 2025 08:38 UTC
Built with Hugo
Theme Stack designed by Jimmy