SSH Key Authentication on Linux Server: Easy Setup Tutorial

NeuralNine · Beginner ·🛠️ AI Tools & Apps ·1y ago
Today we learn how to set up SSH key authentication on Linux servers. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 💼 Services 💼 💻 Freelancing & Tutoring: https://www.neuralnine.com/services 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm

What You'll Learn

Sets up SSH key authentication on Linux servers using SSH protocol

Full Transcript

what is going on guys welcome back in this video today we're going to learn how to set up SSH key authentication on a server and how to then connect to the server using a private key and not a password so let us get right into [Music] ited all right so we're going to learn how to set up SSH key authentication on a server in this video today which means that we're going to be able to authenticate ourselves using a private key rather than a password and and the only thing that you need for this video is some sort of server that you can use you can use a virtual machine on your computer you can use uh any other computer in your local network if you have one uh you can use a server that you rented online you can use multipass which I recently made a video on it doesn't really matter you just need some server uh where you can set up the authentication so where you can put the public key so the idea is we're going to generate a key pair a private key and a public key and the public key is like uh the public information that everyone can have that is um what is needed to check if something is you if some key belongs to you or not so the public key is public information you can put it on a website you can put it on Twitter it doesn't matter everyone can have it uh and it's actually good if people have it because then they can authenticate or that they can check if you are the person trying to connect and the private key is secret information that only you have and it's the only thing that is going to um to to authenticate you as the person that the public key belongs to so the public key is like a checking tool tool and the private key is the thing that the checking tool is going to recognize as being the correct thing that allows for uh the connection so that's the basic idea and what we're going to do first is we're going to open up the terminal and create such a key pair if you don't have one you can also reuse an existing one if you have one uh and I'm going to create here a new directory let's call it key directory doesn't really matter uh and in this directory here I'm going to generate a key pair SSH key gen is the command uh and then I can do uh I can provide a path so I'm going to call this now my uh my connection key and uh then I can use a passphrase if I want to so I can uh secure this with a passphrase I'm going to leave this empty for this video uh the only thing that happens here is that if you provide a passphrase in order to be able to use the key you need to provide a password so you can protect it like that I'm going to just leave that uh empty for the sake of this video and then I get two things I get the my connection key and the my connection key. poop and this is the public key you need to somehow get this onto the server to signal to the server that this is the corresponding key uh to some private key that the server of course doesn't know but this is the um corresponding key which is going to allow you to check if the connection is coming from the correct person from the correct key um so for this video what I'm going to do is I'm going to use multipass again again it doesn't matter what you use you can just connect to your server using SSH and use SCP which I also made a video about recently to get your public key onto the server you can use FTP you can also put your key on a website and then go to the server and download it from the website it doesn't really matter you just need to somehow get your public key onto the server and this can be done using SCP if you already have a connection uh again I have a video on this or in the case of multipass if you want to do this on a virtual machine here you can just use the command multipass transfer which is just going to transfer the file using the multipass command so uh multipass list in my case is already a machine here again all you have to do to create a multipass instance if you don't have one is multipass launch and uh then a name so D- name and some name um and in my case now I'm going to just use the existing one so multipass transfer and uh then I'm going to use the path to this directory here so home uh neural 9 desktop key directory and I'm going to upload the public key so connection key. poop and this is going to be uploaded to some name which is the machine so the name of the virtual machine here and I'm going to upload this to home BTU because that's default user here and then SSH if the directory doesn't exist you have to create it in the case of root it's just root sl. SSH uh and again this is just the way I did it for the video it doesn't matter how you do it you can also connect to the server and do a w get command to download it from somewhere you just have to get somehow this key onto the server into the SSH directory uh and then you need to also connect to the server for example using a password or by already being physically present at the server maybe you have a keyboard there uh or by doing anything else that get gets you a connection to the server in my case it's a multipass shell command um on some name and now I'm on the server so the two things again I repeat what you have to do is you have to connect to the server somehow and you have to upload your key to the SS H directory here so in my case now you can see I have the my connection key. poop file on the server and all I have to do now to authenticate this or to authorize this key is I have to say cat my connection key so read the content in this case it just reads the content and then two angle brackets two closing angle brackets or greater than signs uh and I want to write this to the authorized Keys file so I get the content of this and I append it to the authorized Keys file it's very important that you use two angle brackets not one because otherwise you're just overwriting all the authorized Keys you want to use two to append the key to the already existing Keys uh and of course create this file if it doesn't exist so just run this command and then we can just exit and what I can do now is I can connect using SSH so I can say SSH and then um just Ubuntu add or actually I need dip address so multipass list uh I want to connect to this IP address so bu want to add 10.3.1 18166 in this case now it's not going to work because I don't have a public key but if I provide dasi and then my connection key which is the private key then this is going to allow me to connect to the server without a password without anything and I can also of course copy this connection so I can um copy this key so I can copy the private key uh to my user directory. SSH and I I can do the same thing actually with the uh public key so like this um and I'm not sure if I have to restart my shell but then I can or I should be able to just say multipass uh list to get the IP address and then SSH and then one to at 10.3.1 18166 and this connects me automatically because it recognizes the key in my SSH directory uh that's the basic idea here now I can take this one step further and add a configuration to my uh known hosts file uh I think that's the that's the correct file uh or actually it's the config SSH file I think uh so we need to go to SSH and here I have the config file so if I go into config there are a couple of things that I have to censor here um but what you see here is I have a bunch of hosts to find and what I can do now is I can add a new entry so let me just resize this a little bit um I'm going to add here host and I'm going to call this local Das Ubuntu and then I'm going to say the user that I want to use for the connection is buntu and the host name is the IP address so just run a multipass list again copy this IP address here and then just pass it here and that is basically it so I can then close this clear uh exit rerun this and then I should be able to just say SSH local a bunch to and there you go it connects me to the server because now I have an alias in my config so this is how you can easily set up uh SSH key authorization on a server so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting a like button and leave a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you in the next video and bye for
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

Related AI Lessons

Up next
I Asked ChatGPT to Apply to 500 Jobs (8 Interviews in 48 Hours)
Sabrina Ramonov 🍄
Watch →