Skip to content

Instantly share code, notes, and snippets.

@KreAch3R
Created December 16, 2018 23:06
Show Gist options
  • Save KreAch3R/34e566caf79681ac438f3f155e2b6641 to your computer and use it in GitHub Desktop.
Save KreAch3R/34e566caf79681ac438f3f155e2b6641 to your computer and use it in GitHub Desktop.
Everyone should know how to use ssh in linux.

SSH 101

1. INSTALLING SSH SERVER

ON SERVER:

Ubuntu guide: https://help.ubuntu.com/community/SSH/OpenSSH/Configuring

sudo apt-get install openssh-server
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.factory-defaults
sudo chmod a-w /etc/ssh/sshd_config.factory-defaults
sudo gedit /etc/ssh/sshd_config

Change the PasswordAuthentication to "no" and "Port" to another one of your choosing

For restarting the daemon, use one of these:

sudo restart ssh
sudo systemctl restart ssh
sudo service ssh restart

Open the "Port", per your router instructions

Portforward help: http://portforward.com/

2. SSH Keys

Ubuntu guide: https://help.ubuntu.com/community/SSH/OpenSSH/Keys

ON SERVER:

mkdir ~/.ssh
chmod 700 ~/.ssh

Command to create a new key:

cd ~/.ssh
ssh-keygen -t rsa -b 4096

It will ask you for a name, use a name that shows which device is going to connect to this server. Ex: id_nexus5
Install the PUBLIC key of what you just created in your authorized_keys

cp authorized_keys authorized_keys_Backup
cat id_nexus5.pub >> authorized_keys

ON CLIENT:

Copy the PRIVATE key over with whatever means necessary (the id_nexus5 file)
Use it in the ~/.ssh/config

Host Server
    HostName www.server.example or IP
    Port 1234
    IdentityFile ~/.ssh/id_nexus5

3. CONNECT

ssh Server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment