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
Copy link

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
Copy link

sumitmanchanda01 commented Jul 8, 2018

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

@bradtraversy
Copy link
Author

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
Copy link

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
Copy link

gopibabus commented Oct 29, 2018

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

@Berenddeperend
Copy link

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
Copy link

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
Copy link

ggallovalle commented Sep 4, 2019

Really good, thanks for sharing

@walidabou
Copy link

walidabou commented Oct 5, 2019

Just awesome! Simple & Useful

@Kibza
Copy link

Kibza commented Oct 14, 2019

Awesome content!

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

@mouadTaoussi
Copy link

mouadTaoussi commented Dec 20, 2019

Thank You Brad You're Brilliant!

@mart3y
Copy link

mart3y commented Jun 2, 2020

Thank's Brad

@vimal-verma
Copy link

vimal-verma commented Sep 1, 2020

Thank's a lot!

@iam-amanxz
Copy link

iam-amanxz commented Oct 20, 2020

Thanx sir

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

@NabeelYousafPasha
Copy link

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
Copy link

bruno-0 commented Dec 15, 2020

I can't Thank you enough

@shark159
Copy link

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

@Melford-D
Copy link

Melford-D commented May 10, 2021

Thanks for the assistance, Brad!

@abhishek17569
Copy link

abhishek17569 commented May 24, 2021

Thanks a lot

@Fraol123
Copy link

Fraol123 commented Aug 13, 2021

thanks very helpful video

@yorkshire-pudding
Copy link

yorkshire-pudding commented Dec 3, 2021

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 "your_email@example.com"

@basirchand
Copy link

basirchand commented Feb 28, 2022

Great work.

@CecilDever
Copy link

CecilDever commented May 17, 2022

Hello, thanks for sharing this information with us. It is really very useful for me. I am working on a project and for that I am searching for information online regarding my project. When I was searching for it online, I also found a site in which I have found legit edu birdie reviews. I read those reviews because I want to hire an essay writer to complete my assignments so that I can concentrate on my on going project.

@olakunlebalogun
Copy link

olakunlebalogun commented May 26, 2022

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!

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