Secure shell file system

Updated: 24 June 2023

Mount directory on remote server over ssh

sshfs user@example.com:/remote/folder/path /local/folder/path \
-o IdentityFile=/full/path/to/private/key/file \
-o allow_other

Unmount directory mounted with sshfs above

fusermount -u PATH

scp

Updated: 04 April 2024

scp — OpenSSH secure file copy.

Copy a file from B to A while logged into B

scp /path/to/file username@a:/path/to/destination

Copy a file from B to A while logged into A

scp username@b:/path/to/file /path/to/destination

Copy a directory and the contents

scp -r username@the_host:/etc/nginx /home/chris/nginx-conf-backup

ssh port forwarding

Updated: 16 November 2023

What’s ssh port forwarding and what’s the difference between ssh local and remote port forwarding

-R Specifies that connections to the given TCP port or Unix socket on the remote (server) host are to be forwarded to the local side.
-L Specifies that connections to the given TCP port or Unix socket on the local (client) host are to be forwarded to the given host and port, or Unix socket, on the remote side.

Socks

Updated: 12 September 2022

Socks tunnel

ssh -D 8123 -f -C -q -N user@example.com

-D: Tells SSH that we want a SOCKS tunnel on the specified port number
-f: Forks the process to the background
-C: Compresses the data before sending it
-q: Uses quiet mode
-N: Tells SSH that no command will be sent once the tunnel is up

Verify that the tunnel is up and running:
ps aux | grep ssh

If using -f close the tunnel
kill <process id>

ssh

Updated: 30 March 2024

Prefer password authentication over public key

ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no user@example.com

Use a non-standard port

ssh user@192.168.1.1 -p 26