Accessing Remote Machines Using SSH (2024)

Software developers need a way to access remote computers from their own. Why? Maybe to send some data or to execute commands. It’s a routine practice.

There are a variety of programs that give developers this functionality. Telnet is a terminal program that allows users to login to remote computers on the same network. Ftp provides a way to transfer files between computers. They have been around for a long time, but their weakness lies in the fact that they lack security.

SSH, or Secure Socket Shell, provides users with secure access to remote machines via an encrypted connection. All data sent from the client (your computer) is encrypted. Only when the data reaches the remote server will it decrypt. The process of data encryption is transparent. It happens behind the scenes and will not interrupt your workflow. This is a huge benefit. Tools like telnet and ftp don’t provide this layer of security.

One of the main advantages to using SSH are SSH keys. They are a cryptographic public/private key pair used for authentication. They always come in twos. The private key is stored on the client. The public key is stored on the remote machine.

When a user makes an attempt to connect to a remote machine via SSH, the protocol will check the user’s computer for the private key that matches the public key stored on the remote machine. If there is a match, the connection is successful. No password needed! You can even add a passphrase for added security, but we’ll touch on that later.

There are two situations that come to mind.

  1. Logging in to a remote server
  2. Accessing GitHub

If you are accessing a remote server for professional use, there’s a damn good chance you’re already using SSH keys. If not, read on.

If you own a private server and you’re not using SSH keys for authentication, it’s time to start thinking about it. I’ll walk you through the process.

Note: SSH is widely available on most operating systems, but the instructions below have all been executed on Mac OS.

These steps will help you set up SSH keys on your own private server. All commands will be entered through the terminal.

Step 1: Generate SSH Keys

Open the terminal on your local machine. Run the following command:

ssh-keygen -t rsa

The -t option specifies what type of key to generate. We've specified a key with the type rsa. It is just a type of key based on the RSA algorithm.

There are number of options you can add to the command above. For instance, GitHub’s documentation for generating SSH keys uses the -b option, which lets you specify how many bits in the key. Type man ssh-keygen in your terminal for more documentation.

Step 2: Name your SSH keys

After entering the command, you should get this output:

Generating public/private rsa key pair. Enter file in which to save the key(/Users/<local_user>/.ssh/id_rsa)

<local_user> refers to your local computer's current user.

The terminal instructs us to enter the name of a file in which we want our private key to be saved. You have 2 options:

  1. Choose the default filename id_rsa
  2. Provide your own unique filename

Two important things to note here:

  • If you plan on having multiple SSH keys, it’s best to name each one uniquely.
  • If you decide to provide a unique filename, you must type in the complete file path along with the filename

Personally, I append a unique word after id_rsa that describes which remote machine the key will be used to connect to. My GitHub SSH key is named id_rsa_github. The key for my personal server is id_rsa_website.

Hit Enter to choose the default id_rsa filename, or type in your own along with the file path /Users/<local_user>/.ssh/ and then hit Enter.

Step 3: Enter a passphrase (optional)

After entering the name of the file that you want to save your SSH key to you’ll get the following output:

Enter passphrase (empty for no passphrase):

What is a passphrase you ask? It’s an added layer of security on top of your SSH keys. Think of it as a password on top of a password. If you choose to go with a passphrase, you’ll be prompted to enter it every time the SSH protocol authenticates your private SSH key.

You may be thinking, “But Jake, isn’t the purpose of SSH keys to avoid typing a password every..single..time?”

Well, no. Not really. There is a benefit that you don’t have to memorize a password for every remote server you need access to. But that’s not the purpose. A passphrase just adds more security.

The downside of course is the continuous prompt to enter said passphrase. This will annoy you eventually. Trust. There are ways to disable the passphrase prompt, but I will not go over them in this post.

For the sake of this write up, let’s pass on the passphrase (no pun intended). Click Enter twice and let's move on.

You should then get some funky output telling you that your SSH keys have been saved to two files:

/Users/<local_user>/.ssh/<filename> /Users/<local_user>/.ssh/<filename>.pub

Notice that two keys have been generated. The first one is your private key, which will be stored on your local computer. The second is the public key. It should be a dead giveaway because of the .pub extension. This is the key that will be placed on the remote machine.

Step 4: Move the public key to the remote machine

The public key has to be placed on whatever remote machine you plan on accessing via SSH. On Mac it’s pretty simple to do this.

In your terminal, enter:

ssh-copy-id -i ~/.ssh/<public_key_file> <user>@<remote machine>

ssh-copy-id moves the public key file specified with -i ~/.ssh/<public_key_file> from your computer to <remote machine>. It will be stored in the file ~/.ssh/authorized_keys in the directory of <user>.

<user> should be the user you are attempting to login to <remote machine> with.

If you only have one public key file in your local ~/.ssh directory, you can omit the -i ~/.ssh/<public_key_file> option. This is really only necessary if you have multiple public keys, because ssh-copy-id needs to know which key you want to move.

After you run the command, you’ll be presented with some output that might look alarming at first glance. Don’t worry. It’s only because this is the first time you’re attempting to authenticate with the remote machine via SSH keys. Follow the terminal instructions and you’ll be all set!

Step 5: Test your connection

Go ahead and attempt to login to the remote machine using:

ssh <user>@<remote machine>

If you chose to go with a passphrase in step 3, you’ll be prompted to enter it. If not, you will notice that you’ve logged in to the remote machine without typing a password at all. Success! You’re authenticated!

I hope this quick write up proves useful to you. SSH keys are not only a secure way of logging in to remote servers, but are quite convenient. If you have any questions, feel free to reach out to me on Twitter. Happy hacking!

Accessing Remote Machines Using SSH (2024)

FAQs

How to access remote machine using SSH? ›

In the PuTTY configuration window, do the following:
  1. Go to Connection -> SSH -> Tunnels.
  2. Type in the source port number in the Source port field.
  3. Type the VNC server address and port in the Destination field.
  4. Start the SSH session as you normally would.
  5. Connect to your server with a VNC client of your choice.
Nov 23, 2023

How to access virtual machine using SSH? ›

To connect to the running VM
  1. Locate the address of the SSH service. Port opening type. ...
  2. Use the address in a terminal emulation client (such as Putty) or use the following command line to access the VM directly from your desktop SSH client:
  3. ssh -p <port> user@<ip-address-or-hostname>

How is SSH used for remote management? ›

SSH encrypts and authenticates all connections. SSH provides IT and information security professionals with a secure mechanism to manage SSH clients remotely. Rather than requiring password authentication to initialize a connection between an SSH client and server, SSH authenticates the devices themselves.

How to Remote Desktop through SSH? ›

To start an RDP session, or connect to an existing one:
  1. Open a terminal (on MacOS or Linux) or cmd (on Windows 10 1809 or later), and type ssh myutorid@rdp1.teach.cs.toronto.edu -L3388:localhost:3389. ...
  2. When prompted, log in using your Teaching Labs password.
  3. Once logged in, leave the ssh session running; don't exit.

How do I access devices via SSH? ›

Follow these steps:
  1. Connect via SSH Command. Open a terminal and enter the following command: ssh @ . For example, if the IP address is 192.168. ...
  2. Enter Yes to Continue. When prompted with a warning message that says "The authenticity of host 'xxx' can't be established", enter "yes" to continue with the connection.
Feb 21, 2023

How to login to a server using SSH? ›

Connecting to your Dedicated Server via Terminal
  1. Open the terminal on your computer.
  2. Type ssh, followed by a space. ...
  3. If you see a message stating “Are you sure you want to continue connecting” type yes, then click the Enter key.
  4. You will then be prompted to enter your password.
Feb 21, 2024

How do I access SSH server remotely? ›

To initiate an SSH connection to a remote system, you need the Internet Protocol (IP) address or hostname of the remote server and a valid username. You can connect using a password or a private and public key pair. Because passwords and usernames can be brute-forced, it's recommended to use SSH keys.

How to connect two virtual machines using SSH? ›

You create an SSH key pair, add the public key to a VM, and connect to the VM by running the virtctl ssh command with the private key.

What is the SSH protocol? ›

What is the Secure Shell (SSH) protocol? The Secure Shell (SSH) protocol is a method for securely sending commands to a computer over an unsecured network. SSH uses cryptography to authenticate and encrypt connections between devices.

How does SSH work step by step? ›

The steps involved in creating an SSH session go like this:
  1. Client contacts server to initiate a connection.
  2. The server responds by sending the client a public cryptography key.
  3. The server negotiates parameters and opens a secure channel for the client.
  4. The user, through their client, logs into the server.
May 21, 2020

What is the SSH protocol for remote login? ›

SSH Protocol – Secure Remote Login and File Transfer
  1. The SSH protocol (also referred to as Secure Shell) is a method for secure remote login from one computer to another. ...
  2. The public key authentication method is primarily used for automation and sometimes by system administrators for single sign-on.

What is the main advantage of using SSH protocol for a remote connection? ›

The main advantage of SSH is the use of encryption to ensure the secure transfer of information between the client and the server. SSH allows users to execute shell commands on a remote computer in the same way as if they were sitting in front of the physical computer.

How to remotely access another computer using SSH? ›

To connect to a remote computer, click on the Session button (top left) and select the ssh tab. Enter the name or IP of the remote computer in “Remote host”. Check the “Specify username” box and write your user name in the text field. Then, click OK.

What is the difference between Remote Desktop and SSH? ›

RDP: Relies primarily on user credentials for authentication, potentially vulnerable to password-based attacks if weak passwords are used. SSH: Offers diverse authentication methods, including password-based, public-key, and multi-factor authentication, enhancing access control and security.

How do I access Remote Desktop remotely? ›

On your Windows, Android, or iOS device: Open the Remote Desktop app (available for free from Microsoft Store, Google Play, and the Mac App Store), and add the name of the PC that you want to connect to (from Step 1). Select the remote PC name that you added, and then wait for the connection to complete.

How to connect to SSH server remotely? ›

What is the Secure Shell (SSH) protocol? The Secure Shell (SSH) protocol is a method for securely sending commands to a computer over an unsecured network. SSH uses cryptography to authenticate and encrypt connections between devices.

How to run a remote command over SSH? ›

How to Run or Execute Remote Linux Commands over SSH
  1. Find hostname of the server the usual way.
  2. Find hostname of the server using a single ssh command.
  3. Run bash aliases over ssh.
  4. Run multiple commands over ssh.
  5. Run script on remote server over ssh.
  6. Run script on remote server using sudo over ssh.
Jul 5, 2024

How to connect to a machine using SSH private key? ›

Once your SSH key pair is generated, you need to place the public key on the server.
  1. Use the command `ssh-copy-id user@your_server_ip` to copy the public key. Replace `user` with your username and `your_server_ip` with your server's IP address.
  2. Enter your password when prompted.
Jul 10, 2019

How do I access SSH server from anywhere? ›

Remote access to the SSH server running in your Linux server requires installing and running a secure remote access software (a VPN like software) on the Linux server. Once the remote access software is installed on the Linux server, the Linux server device can be securely accessed from anywhere in the world.

Top Articles
15 Best Canadian Blue Chip Stocks for March 2024
1 Stock I Wouldn't Touch With a 10-Foot Pole | The Motley Fool
Find All Subdomains
Chalupp's Pizza Taos Menu
Wild Smile Stapleton
Walgreens Alma School And Dynamite
Call of Duty: NEXT Event Intel, How to Watch, and Tune In Rewards
Minn Kota Paws
Purple Crip Strain Leafly
Oscar Nominated Brings Winning Profile to the Kentucky Turf Cup
Reddit Wisconsin Badgers Leaked
Erskine Plus Portal
Echat Fr Review Pc Retailer In Qatar Prestige Pc Providers – Alpha Marine Group
Alexander Funeral Home Gallatin Obituaries
Hellraiser III [1996] [R] - 5.8.6 | Parents' Guide & Review | Kids-In-Mind.com
Nick Pulos Height, Age, Net Worth, Girlfriend, Stunt Actor
Northeastern Nupath
The Pretty Kitty Tanglewood
Canvasdiscount Black Friday Deals
Hannaford To-Go: Grocery Curbside Pickup
Wisconsin Volleyball Team Boobs Uncensored
Bocca Richboro
Cylinder Head Bolt Torque Values
Mastering Serpentine Belt Replacement: A Step-by-Step Guide | The Motor Guy
Craigslist Middletown Ohio
Gridwords Factoring 1 Answers Pdf
Otis Offender Michigan
Mrstryst
Urban Blight Crossword Clue
Junee Warehouse | Imamother
How to Destroy Rule 34
Go Smiles Herndon Reviews
Magicseaweed Capitola
Pitchfork's Top 200 of the 2010s: 50-1 (clips)
Collier Urgent Care Park Shore
Blasphemous Painting Puzzle
Discover Wisconsin Season 16
Join MileSplit to get access to the latest news, films, and events!
Walmart Pharmacy Hours: What Time Does The Pharmacy Open and Close?
Craigslist Farm And Garden Reading Pa
Exam With A Social Studies Section Crossword
Sour OG is a chill recreational strain -- just have healthy snacks nearby (cannabis review)
Exploring the Digital Marketplace: A Guide to Craigslist Miami
Random Animal Hybrid Generator Wheel
Costco The Dalles Or
Crigslist Tucson
Blog Pch
Mikayla Campinos Alive Or Dead
How To Win The Race In Sneaky Sasquatch
Parks And Rec Fantasy Football Names
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 5860

Rating: 4.9 / 5 (69 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.