DEV Community

Cover image for Set Up SSH in 1 Minute Setup Like a Pro (With Some Fun Along the Way)
akinsiraifedayo
akinsiraifedayo

Posted on

Set Up SSH in 1 Minute Setup Like a Pro (With Some Fun Along the Way)

Ah, SSH. It's like your tech BFF that lets you teleport into servers without leaving your desk. If you've ever felt like setting it up is a secret handshake only hackers know, I'm here to let you in on the club. Let's do this step-by-step, with a sprinkle of geeky fun.


Step 1: Is SSH Installed?

First things first, let's see if you've got SSH installed. Open your terminal and type:

ssh -V
Enter fullscreen mode Exit fullscreen mode

Pro tip: That's a capital V, not a lowercase v (you're welcome). If it spits out a version number, you're golden. If not, Google how to install SSH for your OS---I believe in you.


Step 2: Head to Your SSH Folder

Run this command to jump into your hidden SSH folder:

cd ~/.ssh/
Enter fullscreen mode Exit fullscreen mode

This is where all your SSH magic happens. Think of it as your secret lair.


Step 3: Generate Your SSH Key

Ready to make some keys? Run this:

ssh-keygen -C "your_email_here"
Enter fullscreen mode Exit fullscreen mode

The -C is just adding a comment, like your email, to the key. Follow the prompts, and when it asks for a name, get creative! Name it something like id_rsa_myserver or id_rsa_mycomputer. Naming things is half the fun.

When it asks for a passphrase, consider adding one. It's like giving your private key an extra layer of protection---a bit like 2FA for your SSH.


Step 4: Check Out Your New Keys

Run this:

ls
Enter fullscreen mode Exit fullscreen mode

You should see two files:

  • id_rsa_something (your private key---NEVER share this)

  • id_rsa_something.pub (your public key---this is the one you'll share with the server)


Step 5: Add the Key to SSH

To use the key you just made, run:

ssh-add id_rsa_name_you_used
Enter fullscreen mode Exit fullscreen mode

Step 6: Share the Public Key

Display the contents of your public key with:

cat id_rsa_name_you_used.pub
Enter fullscreen mode Exit fullscreen mode

Copy it (Ctrl + Shift + C for terminal users). Now hop onto the server or computer you want to connect to.


Step 7: Paste the Key on the Other Computer

On the remote computer, navigate to its SSH folder:

cd ~/.ssh/
Enter fullscreen mode Exit fullscreen mode

Then open the authorized_keys file:

vi authorized_keys
Enter fullscreen mode Exit fullscreen mode

Press i to enter insert mode, and paste the key you copied. It should all be on one line.

When you're done, hit the Escape key, type :wq, and press Enter to save and exit.


Step 8: Connect Like a Boss

Now, back on your computer, connect to the server with:

ssh username@server_or_ip_address -p PORT
Enter fullscreen mode Exit fullscreen mode

When prompted, type yes to add the server to your known hosts. And there you go---you're in! Easy, right?


Bonus Tips for Maximum Coolness

Use Aliases

Tired of typing long commands? Add an alias to your ~/.ssh/config file:

Host myserver
    HostName server_ip_or_hostname
    User username
    IdentityFile ~/.ssh/id_rsa_name_you_used
Enter fullscreen mode Exit fullscreen mode

Now, you can just type:

ssh myserver
Enter fullscreen mode Exit fullscreen mode

Keep It Secure

Never share your private key---like, ever. If you're using keys, disable password logins on the server for extra security.

Debug Like a Pro

If something goes wrong, use:

ssh -vvv username@server_ip_or_hostname
Enter fullscreen mode Exit fullscreen mode

This will give you a play-by-play of what's happening. It's like the director's cut of SSH troubleshooting.


There you have it---your quick-and-fun SSH setup guide! Now you're ready to take over (remote) servers with style. 🎉

Top comments (0)