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 [email protected] -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
هل تصل الرسائل بعد رفع الحظر في الواتس؟ اليك الجواب
Top 10 Digital Banks of 2022
It's Official: Sabrina Carpenter's Bangs Are Taking Over TikTok
Time in Baltimore, Maryland, United States now
Archived Obituaries
T Mobile Rival Crossword Clue
DL1678 (DAL1678) Delta Historial y rastreo de vuelos - FlightAware
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Gt Transfer Equivalency
Robot or human?
Edible Arrangements Keller
83600 Block Of 11Th Street East Palmdale Ca
Hssn Broadcasts
Gma Deals And Steals Today 2022
Huge Boobs Images
Non Sequitur
Google Feud Unblocked 6969
U Break It Near Me
Nine Perfect Strangers (Miniserie, 2021)
My Homework Lesson 11 Volume Of Composite Figures Answer Key
How To Level Up Roc Rlcraft
SuperPay.Me Review 2023 | Legitimate and user-friendly
Mybiglots Net Associates
Airtable Concatenate
Malluvilla In Malayalam Movies Download
Turns As A Jetliner Crossword Clue
Possum Exam Fallout 76
Tu Housing Portal
RFK Jr., in Glendale, says he's under investigation for 'collecting a whale specimen'
De beste uitvaartdiensten die goede rituele diensten aanbieden voor de laatste rituelen
Craigslist Albany Ny Garage Sales
All Things Algebra Unit 3 Homework 2 Answer Key
Mp4Mania.net1
Uhaul Park Merced
Rocketpult Infinite Fuel
Mydocbill.com/Mr
Ludvigsen Mortuary Fremont Nebraska
The Transformation Of Vanessa Ray From Childhood To Blue Bloods - Looper
Nancy Pazelt Obituary
Simnet Jwu
Sand Castle Parents Guide
Booknet.com Contract Marriage 2
Craigslist Minneapolis Com
Brown launches digital hub to expand community, career exploration for students, alumni
Tommy Bahama Restaurant Bar & Store The Woodlands Menu
Nearest Wintrust Bank
Spn 3464 Engine Throttle Actuator 1 Control Command
R Detroit Lions
300 Fort Monroe Industrial Parkway Monroeville Oh
Arre St Wv Srj
Selly Medaline
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.