Skip to content

SSH

Tips about the secure shell (SSH)

Install SSH

Windows

Linux

Setup SSH

Generate a key pair locally (client)

ssh-keygen -t ed25519 -C "your_email@example.com"

The SSH agent will ask you to enter a location to save the keys. e.g. /home/user/.ssh/id_ed25519. Passphrase is optional. Then there will be two SSH key files:

  • ~/.ssh/id_ed25519 is the private key. Protect it at all costs.
  • ~/.ssh/id_ed25519.pub is the public key.

Using different keys for different access points is more secure.

Accessing the remote machine (server)

Edit ~/.ssh/config

mkdir -p ~/.ssh
touch ~/.ssh/config
chmod 600 ~/.ssh/config
nano ~/.ssh/config

Add the following content to set the private key as the IdentityFile.

~/.ssh/config
Host <Your host>
  HostName <remote-ip>
  User <your-name>
  Port <your-port>
  IdentityFile ~/.ssh/id_ed25519

Accessing GitHub repositories via SSH

Edit ~/.ssh/config

~/.ssh/config
Host GitHub
  HostName github.com
  IdentityFile ~/.ssh/id_ed25519

Add the SSH key here, according to 📖 Github docs.

  • Paste the content of the public key, ~/.ssh/id_ed25519.pub to the key field.
  • Add a descriptive label for the new key in the “Title” field.
  • Finally, click the Add SSH key green button. If prompted, confirm your GitHub password.

Test your setup, accept its fingerprint if prompted.

ssh -vT git@github.com

Accept its fingerprint if prompted. If you see “Hi user! You’ve successfully authenticated, but GitHub does not provide shell access” that means login is successful.

Transfer file over ssh

How to copy files through SSH

tar

tar cvf - $localdir | ssh someone@somemachine '(cd destdir && tar xBf -)'

rsync

Use a SSH remote as a source or a destination folder.

rsync -avh /source/folder/ username@nasip:dest/folder/

Secure FTP (SFTP)

Filezilla and WinSCP can access remote servers via the Secure FTP (SFTP) protocol.

Mount remote directory as a disk via sshfs

https://github.com/libfuse/sshfs mounts a remote machine’s directory as a local disk.

sshfs [user@]hostname:[directory] mount-point

To unmount the directory after file operations are done:

fusermount -u mount-point
Last updated on