DEV Community

B. Burt
B. Burt

Posted on • Edited on

Use SSH! All the Cool Kids Are Doing It

Hi! I'm BBurt! And today I'm gonna concisely walk you through setting up Secure Shell Access, of which, I only know a little. haha

So why, if I only know a little, am I trying to explain it? I'm glad you asked!

Let me tell you :)

First of all, not too long ago, I was listening to the fabulous Syntax podcast (it's great, you prolly already know) episode 478 with guest Shawn "Swyx" Wang and he mentioned his own Learn In Public, I was intrigued so I checked it out and read this free chapter. It's good. You should read it.

But so, I'm taking his advice and learning in public!

The other reason I'm writing this is because, you know how they say that if your function is doing too much, or too many things, you should probably refactor, split it up into more than one function?

Well similarly, I was writing this other piece here and it was doing too much. Hence this :)

What the heck is SSH, anyways?

Well, how about a definition?

From Wikipedia:

The Secure Shell Protocol (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution.

Hey, that's us! Remote login and command-line execution.

From GitHub:

Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username and personal access token at each visit. You can also use an SSH key to sign commits.

I'm not sure what happened, normally I don't have to enter my username and password at the command line when fetching or pulling my own code from GitHub. But yesterday I had to do the whole personal-access-token-thing which led me down a rabbit hole, you know how that goes, and I ended up here on StackOverflow.

On my machine, I have it set up to use SSH thanks to doing the course work at The Odin Project. Their instructions for setting up Git to use SSH to access GitHub can be found here. By the way, I highly recommend their course (I'm still working my way through it).

I also highly recommend, if you're wanting to set up SSH, to follow the instructions on that link above, or on GitHub for the official, longer guide, but for the sake of this article, I'm gonna tell you how. The short and sweet of it is as follows (I'm on Linux by the way):

ls ~/.ssh/id_ed25519.pub

to check if you have an ED25519 algorithm SSH key already installed.

If you get no output, or "No such file or directory" from running that command, you can generate a key by entering:

ssh-keygen -t ed25519 -C <your-email>

(I know y'all know better but, you'd put your own email address in there, minus the brackets) then just hit enter and enter again for the two questions after that.

Go to GitHub settings --> on the left-hand side click, "SSH and GPG keys" --> click "New SSH key" --> name it something wonderful, then leave that page as is for a sec, go back to your command line and run:

cat ~/.ssh/id_ed25519.pub

you'll get a long string that ends with your email address, copy that badboy into your clipboard, go back to GitHub and paste er on in there. Then click the "Add SSH key" button.

And that's it! No more having to enter your username and fussing with access tokens just to push or pull your code.

You can test it with:

ssh -T git@github.com

and you'll get a nice little message from GitHub :)

A command-line greeting from GitHub that says, "Hi beeburrt! You've successfully authenticated, but GitHub does not provide shell access."

I know that GitHub currently recommends HTTPS over SSH, but I still like using SSH.

I don't have much at stake, with regard to sending my data over the wire, but I can imagine there are others (journalists, activists, government devs?) that have a lot more on the line where security really IS of the utmost importance. In those cases, I can see how this decision, whether to use SSH or HTTPS, would take a lot of crucial consideration.

That's all. I hope you like my writing, maybe I'll keep it up :) haha Let me know in the comments which one you use, SSH or HTTPS and why.

buy me a coffee!

Top comments (0)