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_ed25519is the private key. Protect it at all costs.~/.ssh/id_ed25519.pubis 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/configAdd the following content to set the private key as the IdentityFile.
Host <Your host>
HostName <remote-ip>
User <your-name>
Port <your-port>
IdentityFile ~/.ssh/id_ed25519Accessing GitHub repositories via SSH
Edit ~/.ssh/config
Host GitHub
HostName github.com
IdentityFile ~/.ssh/id_ed25519Add the SSH key here, according to 📖 Github docs.
- Paste the content of the public key,
~/.ssh/id_ed25519.pubto the key field. - Add a descriptive label for the new key in the “Title” field.
- Finally, click the
Add SSH keygreen button. If prompted, confirm your GitHub password.
Test your setup, accept its fingerprint if prompted.
ssh -vT git@github.comAccept 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-pointTo unmount the directory after file operations are done:
fusermount -u mount-point