Skip to content

Instantly share code, notes, and snippets.

Last active July 3, 2024 15:51
Show Gist options
  • Save bradtraversy/f03df587f2323b50beb4250520089a9e to your computer and use it in GitHub Desktop.
Save bradtraversy/f03df587f2323b50beb4250520089a9e to your computer and use it in GitHub Desktop.
SSH & DevOps Crash Course Snippets

SSH Cheat Sheet

This sheet goes along with this SSH YouTube tutorial

Login via SSH with password (LOCAL SERVER)

$ ssh brad@

Create folder, file, install Apache (Just messing around)

$ mkdir test

$ cd test

$ touch hello.txt

$ sudo apt-get install apache2

Generate Keys (Local Machine)

$ ssh-keygen

Add Key to server in one command

> cat ~/.ssh/ | ssh brad@ "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys

Create & copy a file to the server using SCP

$ touch test.txt $ scp ~/test.txt brad@


Create account->create droplet

Create Keys For Droplet (id_rsa_do)

$ ssh-keygen -t rsa

Add Key When Creating Droplet

Try logging in

$ ssh root@doserver

If it doesn't work

$ ssh-add ~/.ssh/id_rsa_do (or whatever name you used)

Login should now work

$ ssh root@doserver

Update packages

$ sudo apt update

$ sudo apt upgrade

Create new user with sudo

$ adduser brad

$ id brad

$ usermod -aG sudo brad

$ id brad

Login as brad

> ssh brad@doserver

We need to add the key to brads .ssh on the server, log back in as root

$ ssh root@doserver

$ cd /home/brad

$ mkdir .ssh

$ cd .ssh

$ touch authorized_keys

> sudo nano authorized_keys (paste in the key, exit and log in as brad)

Disable root password login

$ sudo nano /etc/ssh/sshd_config

Set the following

PermitRootLogin no

PasswordAuthentication no

Reload sshd service

$ sudo systemctl reload sshd

Change owner of /home/brad/* to brad

$ sudo chown -R brad:brad /home/brad

May need to set permission

$ chmod 700 /home/brad/.ssh

Install Apache and visit ip

$ sudo apt install apache2 -y


Generate Github Key(On Server)

$ ssh-keygen -t rsa (id_rsa_github or whatever you want)

Add new key

$ ssh-add /home/brad/.ssh/id_rsa_github

If you get a message about auth agent, run this and try again

```$ eval `ssh-agent -s````

Clone repo

$ git clone

Install Node

$ curl -sL | sudo -E bash -

$ sudo apt-get install -y nodejs

Install Dependencies

$ npm install

Start Dev Server and visit ip:3000

$ npm start

Build Out React App

$ npm run build

Move static build to web server root

$ sudo mv -v /home/brad/react_otka_auth/build/* /var/www/html

Copy link

Noso4eg commented Nov 8, 2019

Thank's a lot!
This string needs a quote at the end, and the character ">" at the beginning of the string needs to be removed:

Copy link

mouadTaoussi commented Dec 20, 2019

Thank You Brad You're Brilliant!

Copy link

mart3y commented Jun 2, 2020

Thank's Brad

Copy link

Thank's a lot!

Copy link

Thanx sir

Copy link

Polda18 commented Nov 2, 2020

Very useful tutorial I say. I must say something and that's in order to access a self hosted server that doesn't have an easy web access like DigitalOcean has you have to become creative and find different means to copy and paste your public key to the server you're trying to access via SSH. One of the means, probably craziest and best at the same time in case of desktop server would be use of pastebin service with time-limited access. Our server runs desktop version of Ubuntu MATE, running as virtual machine under ProxMox on a physical machine, basically self hosted server. Console is simply just remote monitor and there is no shared clipboard feature so the only way I can copy paste between local machine and guest system on a remote server is using something like pastebin.

Copy link

Thanks very much. Your video been in my YouTube downloaded videos for more than a year. Respect from Pakistan. @brad

Copy link

bruno-0 commented Dec 15, 2020

I can't Thank you enough

Copy link

If you run a server on a machine and then you move back and forth to 2 different networks(you'll have 2 different IPs). Is it possible to register 2 ssh keys in first run to work on both networks? The idea is to connect to server with the same user but in different local networks.

Copy link

mtsafe commented Apr 6, 2021

The command to "Add Key to server in one command" does not end with a double quote. Please fix. Thank you!

Copy link

Thanks for the assistance, Brad!

Copy link

Thanks a lot

Copy link

thanks very helpful video

Copy link

The youtube and gist is really helpful. You may want to update the github section as github recommends the ed25519 algorithm

Paste the text below, substituting in your GitHub email address.
$ ssh-keygen -t ed25519 -C ""

Copy link

Great work.

Copy link

Thanks as always, the journey has been easier with you. l am just getting started with the Linux distro and it's like I don't know anything about it at all, do you or anyone have some resources they can refer me to, it would be of great help... Thanks again Brad!

Copy link

thank you sir i just learned how to be more secure with ssh

Copy link

thank you sir

Copy link

Dbenjamy commented Jan 3, 2023

Small mistake

The bash code for "Add key to server in one command" is missing a closing quotation mark. I don't know how other systems handle it, but in mine it kept expecting more lines until I added a closing quote.

Copy link

thanks brad

Copy link

Thanks brad.

Copy link

Pagadam commented May 15, 2023

Thanks Brad

Copy link

Adooz commented Aug 26, 2023

extremely insightful.

Copy link

OUALIID commented Sep 24, 2023

Thanks brad

Copy link


Copy link

mz3r0 commented Dec 15, 2023

In the "Add key to server in one command" where is the double quote supposed to end?

Copy link

In the "Add key to server in one command" where is the double quote supposed to end?

at the end of the command

Copy link

Thanks for this Brad

Copy link

you're welcome

Copy link

Awesome 🙌

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