SSH, or Secure Shell, is a network protocol that allows you to securely connect to a remote computer. By using SSH keys to connect to your server, you can authenticate yourself to the server without needing a password and add an extra layer of security to your connection. We will be covering the following topics in this tutorial:
- Why you should use SSH keys, and How does it work
- Please check this article on how to generate SSH keys
- How to copy your SSH private or public key to a server from different platforms
- How to login to a server using SSH keys from different platforms
By the end of this tutorial, you should have a solid understanding of how to set up and use SSH keys to securely connect to your server. Let’s get started!
Here’s the video on How to Connect to a Server Using SSH Keys from Windows, Mac, and Linux (+ Bonus Tool):
Commands & Notes as discussed in the video:
How to Connect to Your Server Using SSH Keys ================================================= Common Scenarios: a. To securely access a cloud server from your Local desktop (ex. access from your laptop) b. To securely access a cloud server from another cloud server (ex. access from your private server) Common Platforms/Tools: SSH Terminal for Linux/Mac/Windows: WSL, Powershell, Bitvise SSH Client for Windows THE QUESTION: How Does SSH Keys Authentication Work? 1) Generate the ssh key pair from local or remote 2) Copy the Pub key into the remote server (or download the private key for the local machine to get access) 3) Connect Available Options: Your Choice! 1) Give Permission to your Local Machine from the Cloud (manually authorizing the pub key within the server and downloding private key to local machine to get access). a) cPanel/WHM SSH Keys generation b) Manually through a Standard OS Install Cloud Server -Bitvise SSH Client Method -Powershell or SSH Terminal Method 2) Ask Permission to the Cloud from Local Machine (copying pub key to cloud server): -Bitvise SSH Client Method -Powershell (or SSH Terminal Method) How to Copy Your SSH Public Key to a Remote Server ==================================================== # OPTION 1: Copy your ssh public key to a remote server using ssh-copy-id command from your local machine: ssh-copy-id -i "custom-key.pub" -p22 [email protected] # OPTION 2: Use this command if ssh-copy-id don't work for you (replace w/ correct details): # For existing authorized_keys file a) cat ~/.ssh/id_rsa.pub | ssh -p22 [email protected] 'cat >> ~/.ssh/authorized_keys' # Without existing authorized_keys file b) cat ~/.ssh/id_rsa.pub | ssh -p22 [email protected] "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys" # OPTION 3: Copy the content manually from your ssh public key file, then Login to Remote server and use Echo command (replace w/ correct details from below format): ssh -p22 [email protected] echo "add_your_public_key_content" >> ~/.ssh/authorized_keys # OPTION 4: Copy the content manually from your ssh public key file into the authorized_keys file on the remote server: # Login to the remote server ssh [email protected] -p22 # Use Nano Editor to add public key content (Hit CTRL+O+X to save): nano ~/.ssh/authorized_keys #Also make sure to setup right permissions for the folders and files cd chmod 700 ~/.ssh chmod 600 ~/.ssh/* How to Login to Your Remote Server Using SSH Keys ======================================================= ssh -p22 [email protected] # OR If using a custom port ssh -p22 [email protected] # OR If using a custom key file cd /path/to/key-file ssh -i "key-file" [email protected] # OR If using a custom key file and port cd /path/to/key-file ssh -i "key-file" -p22 [email protected]
If you followed the tutorial step by step, you should be able to connect yourself to your remote server without needing a password using SSH keys from different platforms.
I hope that this tutorial has been helpful in showing you how to set up and use SSH keys to connect to your server.
If you have any questions or need further assistance, please don’t hesitate to reach out. Happy connecting!
? MORE TUTORIALS YOU MIGHT LIKE:
Make Money w/ Websites (FREE Course) https://bit.ly/3zQ6oAJ
FREE Hosting for WordPress (FREE Course) https://bit.ly/3YgZ8ti
Webmaster & SysAdmin Tutorials https://bit.ly/3hgY87E
More FREE Courses & Tutorials https://bit.ly/3hgY87E
Learn more from me by joining my newsletter
Niche Websites for Sale https://mauwiks.com/niche-website-seller
Business Tools & Services I have used https://mauwiks.com/resources
Hire Me for Freelancing Services https://mauwiks.com/freelancing