Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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@192.168.1.29

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/id_rsa.pub | ssh brad@192.168.1.29 "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@192.168.1.29:~

DIGITAL OCEAN

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 id_rsa_do.pub 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

Github

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 git@github.com:bradtraversy/react_otka_auth.git

Install Node

$ curl -sL https://deb.nodesource.com/setup_10.x | 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

@akrishnakumar-splunk

This comment has been minimized.

Copy link

@akrishnakumar-splunk akrishnakumar-splunk commented Jul 8, 2018

How about using Ansible for automating the stuff? It's a DevOps tool for automating the tasks (deployments in this case) or just making changes repetitively (like you wanna repeat a single task every time). It uses SSH and easy to learn (as it's YAML)

Resource: https://www.ansible.com/

@sumitmanchanda01

This comment has been minimized.

Copy link

@sumitmanchanda01 sumitmanchanda01 commented Jul 8, 2018

A ton of thanks Brad !!y You really bring change in My life !!

@bradtraversy

This comment has been minimized.

Copy link
Owner Author

@bradtraversy bradtraversy commented Jul 9, 2018

Akrish, the answer is because this is part of a tutorial. Services like that are good for people that already know how to do these things

@briancalma

This comment has been minimized.

Copy link

@briancalma briancalma commented Jul 16, 2018

Sir how i wish that you will also create a video for deploying LARAVEL using SSH , DIGITAL OCEAN and LEMP Stack.

@gopibabus

This comment has been minimized.

Copy link

@gopibabus gopibabus commented Oct 29, 2018

Thanks Brad, you educating me a lot. Thanks for all your tutorials.

@Berenddeperend

This comment has been minimized.

Copy link

@Berenddeperend Berenddeperend commented Jan 1, 2019

You forgot a closing quote in the 'Add Key to server in one command' part. Other than that, very helpful!

@DV2017

This comment has been minimized.

Copy link

@DV2017 DV2017 commented Feb 17, 2019

Really cool stuff! Awesome, Brad. Thanks a ton. This is a BIG help to beginners like me (sometimes I feel I am always a beginner! :( ... )

@ggallovalle

This comment has been minimized.

Copy link

@ggallovalle ggallovalle commented Sep 4, 2019

Really good, thanks for sharing

@walidabou

This comment has been minimized.

Copy link

@walidabou walidabou commented Oct 5, 2019

Just awesome! Simple & Useful

@Kibza

This comment has been minimized.

Copy link

@Kibza Kibza commented Oct 14, 2019

Awesome content!

@Noso4eg

This comment has been minimized.

Copy link

@Noso4eg 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:
https://gist.github.com/bradtraversy/f03df587f2323b50beb4250520089a9e#add-key-to-server-in-one-command

@mouadTaoussi

This comment has been minimized.

Copy link

@mouadTaoussi mouadTaoussi commented Dec 20, 2019

Thank You Brad You're Brilliant!

@mart3y

This comment has been minimized.

Copy link

@mart3y mart3y commented Jun 2, 2020

Thank's Brad

@vimal-verma

This comment has been minimized.

Copy link

@vimal-verma vimal-verma commented Sep 1, 2020

Thank's a lot!

@iam-amanxz

This comment has been minimized.

Copy link

@iam-amanxz iam-amanxz commented Oct 20, 2020

Thanx sir

@Polda18

This comment has been minimized.

Copy link

@Polda18 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.

@NabeelYousafPasha

This comment has been minimized.

Copy link

@NabeelYousafPasha NabeelYousafPasha commented Dec 9, 2020

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

@bruno-0

This comment has been minimized.

Copy link

@bruno-0 bruno-0 commented Dec 15, 2020

I can't Thank you enough

@shark159

This comment has been minimized.

Copy link

@shark159 shark159 commented Mar 21, 2021

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.

@mtsafe

This comment has been minimized.

Copy link

@mtsafe 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!

@Melford-D

This comment has been minimized.

Copy link

@Melford-D Melford-D commented May 10, 2021

Thanks for the assistance, Brad!

@abhishek17569

This comment has been minimized.

Copy link

@abhishek17569 abhishek17569 commented May 24, 2021

Thanks a lot

@Fraol123

This comment has been minimized.

Copy link

@Fraol123 Fraol123 commented Aug 13, 2021

thanks very helpful video

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