How to Use SSH to Connect to a Remote Server in Linux or Windows (2024)

Introduction

SSH (Secure Shell) is a cryptographic protocol for securely connecting to a remote server over an unsecured network. It is essential for managing remote systems, networking, and communicating with remote servers.

The protocol provides a secure connection between a client and a server. It enables managing other computers, transferring files, and executing commands on a remote machine.

This guide explains how to SSH to a remote server from Windows, Linux, or Mac.

How to Use SSH to Connect to a Remote Server in Linux or Windows (1)

Prerequisites

  • The remote computer must be turned on and have a network connection.
  • The IP address or the name of the remote machine.
  • Permission to access the remote computer.
  • Firewall settings to allow SSH connections.

What Is SSH?

Secure Shell, sometimes called Secure Socket Shell, is a protocol that allows you to securely connect to a remote computer or a server using a text-based interface.

When a secure SSH connection is established, a shell session starts. It enables manipulating the server by typing commands within the client on your local computer.

System and network administrators use this protocol to manage remote servers and machines. Anyone who requires managing a computer remotely in a highly secure manner uses SSH.

Note: SSH and SFTP protocols are frequently conflated, but have unique and distinct roles. Learn about the similarities and differences between SSH and SFTP.

How Does SSH Work?

Both the client and server participate in establishing a secure SSH communication channel. Creating an SSH connection relies on the following components and steps:

  • Client-side component. A client-side component is an application or program used to connect to another machine. The client uses remote host information to initiate the connection through the program. If the credentials are verified, the program establishes an encrypted connection.
  • Server-side component. On the server's side, an SSH daemon constantly listens to a specific TCP/IP port (the default SSH port number is 22) for possible client connection requests. Once a client initiates a connection through the defined port, the SSH daemon responds with the software and the protocol versions it supports. The default protocol version for SSH communication is version 2.
  • Key exchange. The client and server exchange cryptographic keys to create a secure communication channel. The keys help encrypt subsequent communication.
  • Authentication. When establishing a connection, the client provides identification data to the server (as a username/password or SSH keys). If the provided credentials are correct, SSH creates a new encrypted communication session.

Note: For more details, check out our comprehensive guide on how SSH works.

How to Enable an SSH Connection

Since creating an SSH connection requires both a client and a server component, ensure they are installed on the local and remote servers. The sections below demonstrate how to install a client-side and server-side component depending on the OS.

Install SSH Component on Mac

macOS typically has the SSH client preinstalled. Open the terminal and check with the following command:

ssh -v
How to Use SSH to Connect to a Remote Server in Linux or Windows (2)

The command shows the installed SSH version. To use a third-party SSH application, such as OpenSSH, use the following Homebrew command:

brew install openssh

Note: If you don't have Homebrew installed, check out our guide on how to install Homebrew on Mac.

The installation allows managing a separate version from the system's default SSH component. Alternatively, install PuTTY on macOS to use a GUI-based SSH client.

To enable SSH server remote login on a macOS, do the following:

1. Go to System Settings.

2. Click General in the left menu.

3. Locate and open Sharing.

How to Use SSH to Connect to a Remote Server in Linux or Windows (3)

4. Enable Remote Login to allow SSH access to the device.

How to Use SSH to Connect to a Remote Server in Linux or Windows (4)

Install SSH Component on Linux

Some Linux distributions do not have an SSH component installed by default. Typical solutions are installing OpenSSH or a GUI solution, such as the PuTTY client for Ubuntu.

Installing OpenSSH requires access to the terminal on the server and the computer you use for connecting. The steps for installing and setting up the OpenSSH client and server component are below:

1. To install the client component, run one of the following commands on the client machine:

For Debian/Ubuntu-based Systems:

sudo apt install openssh-client

For Red Hat-based systems (such as CentOS or Fedora):

sudo dnf install openssh-clients
sudo yum install openssh-clients

2. Next, install the server component on the server machine:

For Debian/Ubuntu-based Systems:

sudo apt install openssh-server

For Red Hat-based systems (such as CentOS or Fedora):

sudo dnf install openssh-server
sudo yum install openssh-server

3. After installing the components, the SSH service automatically starts. View the service status with:

systemctl status sshd
How to Use SSH to Connect to a Remote Server in Linux or Windows (5)

In case the service is not running, run it with the following command:

sudo systemctl start sshd

The command does not print an output.

4. To have the service start automatically on boot, run:

sudo systemctl enable sshd

Enabling the sshd service starts it during the boot process.

Note: On some systems, sshd is the service name alias, and the commands will not work. In that case, replace sshd with ssh in the previous commands.

Install SSH Component on Windows

SSH is not a default component on Windows systems. Windows 10 and later versions include a native OpenSSH app.

To enable SSH, do the following:

1. Open Settings -> Apps & features -> Optional features.

How to Use SSH to Connect to a Remote Server in Linux or Windows (6)

2. Click the Add a feature button.

How to Use SSH to Connect to a Remote Server in Linux or Windows (7)

3. Search for and install the OpenSSH app.

How to Use SSH to Connect to a Remote Server in Linux or Windows (8)

Alternatively, a popular option is to install PuTTY on Windows or to use a Linux distribution through the WSL (Windows Subsystem for Linux) feature.

How to Connect via SSH

After installing and setting up the SSH client and server on each machine, you can establish a secure remote connection. To connect to a server, do the following:

1. Open the command line/terminal window and run the following ssh command:

ssh [username]@[host_ip_address]

Provide the username and host IP address. If the username is the same as the local machine, omit the username from the command. To test if SSH is installed correctly, try creating an SSH connection to localhost.

2. When connecting to the server for the first time, a message appears asking to confirm the connection. Type yes and press Enter to confirm the remote server identification on the local machine.

3. Provide the password when prompted and press Enter. The screen does not display characters as you are typing.

How to Use SSH to Connect to a Remote Server in Linux or Windows (9)

A digital signature ECDSA key fingerprint helps authenticate the machine and establishes a connection to the remote server.

If the computer you are trying to connect to is on the same network, then it is best to use a private IP address instead of a public IP address.

Note: Learn about the differences between a private and public IP address and the roles of each.

Additionally, ensure the correct TCP port listens for connection requests and that port forwarding settings are correct. The default port number is 22 unless the configuration has been changed. You may also append the port number after the host IP address.

When using a port number, the following two examples are valid:

ssh [username]@[host_ip_address]:[port]
ssh [username]@[host_ip_address] -p [port]

If there are any issues connecting to the remote server, make sure that:

  • The IP address of the remote machine is correct.
  • The port the SSH daemon is listening to is not blocked by a firewall or forwarded incorrectly.
  • The username and password are correct.
  • The SSH software is installed correctly.

Note: If SSH responds with a message "Connection refused", please refer to our article How To Fix The SSH "Connection Refused" Error for possible reasons and solutions.

SSH Further Steps

After establishing a connection to your server using SSH, there are additional steps to improve SSH security. Default values should always be changed; not changing them leaves a server vulnerable to attacks. Some of the suggestions require editing the SSH configuration file.

Below is a list of practical steps to secure the SSH connection:

Change the Default TCP Listening Port

Instead of using the default port 22, try a higher number. Avoid using a port number that is easy to guess, such as 222, 2222, or 22222.

Use SSH Key Pairs for Authentication

Passwordless SSH login is safer and allows logging in without using an SSH key pair (which is faster and more convenient).

Disable Password-Based Logins on Your Server

If your password gets cracked, this will eliminate the possibility of using it to log into your servers. Before you turn off the option to log in using passwords, ensure that authentication using key pairs works.

Disable Root Access

Removing default root access to your server makes accessing the root account harder for unwanted solicitors. Instead, use a regular account with the su - command to switch to a root user.

Use TCP Wrappers

TCP wrappers enable restricting access to specific IP addresses or hostnames. Configure which host can connect by editing the /etc/hosts.allow and /etc/hosts.deny files. Note that the first file has higher authorization than the second.

For example, to allow SSH access to a single host, first deny all hosts by adding these two lines in the /etc/hosts.deny file:

sshd : ALLALL : ALL
How to Use SSH to Connect to a Remote Server in Linux or Windows (10)

Then, in the /etc/hosts.allow file, add a line with the allowed hosts for the SSH service:

sshd : 10.10.0.5, LOCAL

How to Use SSH to Connect to a Remote Server in Linux or Windows (11)

The host can be an IP address, an IP range, or a hostname.

Secure Login Information and Employ Multilayer Security

Use different methods to limit SSH access to your servers, or use services that block anyone using brute force to gain access. Fail2ban is one example of such a service.

VNC Over SSH

In a Virtual Network Computing (VNC) environment, it is possible to encrypt connections using SSH tunneling via the ssh command and through PuTTY.

To tunnel VNC connections over SSH, run the following command in the command line/terminal:

ssh -L [local_address]:[local_port]:[VNC_server_address]:[VNC_server_port] -N -f -l [username] [hostname_or_IP]

The command does the following:

  • ssh. Starts the SSH client program on your local machine and enables secure connection to the SSH server on a remote computer.
  • -L [local_address]:[local_port]:[VNC_server_address]:[VNC_server_port]. The local address and port for the client on the local machine are to be forwarded to the specified server host and port of the remote machine.
  • -N. Forwards ports without executing a remote command.
  • -f. Sends SSH to the background after the password is provided. This allows typing commands in the local terminal.
  • -l [username]. The username for connecting to the SSH server.
  • [hostname_or_IP]. The hostname or IP of the SSH server.

You can also connect to a remote server via SSH tunnel using PuTTY. 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.

How to Use SSH to Connect to a Remote Server in Linux or Windows (12)

4. Start the SSH session as you normally would.

5. Connect to your server with a VNC client of your choice.

Conclusion

You should now be able to connect to a remote server with SSH. There are many other methods to establish a connection between two remote computers, but the ones covered here are most common and secure.

Next, see how to mount a remote file system using SSH with the SSHFS client.

As an enthusiast with a deep understanding of SSH (Secure Shell) and its applications, let me provide you with comprehensive insights into the concepts discussed in the article.

SSH Overview: SSH, or Secure Shell, is a cryptographic protocol designed for secure communication over an unsecured network. It plays a crucial role in managing remote systems, facilitating secure connections, file transfers, and command execution on remote machines.

Purpose of SSH: The primary purpose of SSH is to establish a secure connection between a client and a server. This secure connection allows system and network administrators to manage remote servers and machines securely. SSH is widely used by anyone who needs to remotely manage a computer in a highly secure manner.

SSH vs. SFTP: While SSH and SFTP (Secure File Transfer Protocol) are sometimes conflated, it's crucial to recognize their unique roles. SSH is a protocol for secure connections, whereas SFTP is specifically designed for secure file transfers. Understanding the distinctions between the two is essential for effective system administration.

How SSH Works: SSH works through a series of steps, involving client-side and server-side components:

  • Client-side component: Initiates the connection using remote host information.
  • Server-side component: Listens on a specific TCP/IP port for client connection requests.
  • Key exchange: Involves the exchange of cryptographic keys to establish a secure communication channel.
  • Authentication: The client provides identification data (username/password or SSH keys) to the server, and if credentials are correct, an encrypted communication session is established.

Enabling SSH Connection: The article provides detailed steps for enabling SSH connections on different operating systems:

  • Mac: Checking SSH version, installing OpenSSH using Homebrew, and enabling remote login.
  • Linux: Installing OpenSSH on both client and server machines.
  • Windows: Enabling OpenSSH via system settings or installing PuTTY.

Connecting via SSH: After setting up the SSH client and server, connecting to a remote server involves running the ssh command with the username and host IP address. The article emphasizes checking for correct IP addresses, firewall settings, and SSH software installation.

SSH Security Best Practices: The article outlines crucial steps to enhance SSH security:

  • Changing the default TCP listening port.
  • Using SSH key pairs for authentication.
  • Disabling password-based logins.
  • Disabling root access and using a regular account.
  • Implementing TCP wrappers to restrict access based on IP addresses.
  • Employing multi-layer security and monitoring tools like Fail2ban.

VNC Over SSH: The article introduces tunneling VNC connections over SSH, enhancing the security of Virtual Network Computing environments. It provides command-line instructions and details on configuring PuTTY for this purpose.

Conclusion: The comprehensive guide concludes with the assurance that readers should now be able to connect to a remote server securely using SSH. It hints at further topics, such as mounting a remote file system using SSH with the SSHFS client, suggesting a continued exploration of secure remote management techniques.

In summary, this article serves as a valuable resource for individuals seeking to understand, implement, and optimize SSH connections for secure remote server management across various operating systems.

How to Use SSH to Connect to a Remote Server in Linux or Windows (2024)

FAQs

How to Use SSH to Connect to a Remote Server in Linux or Windows? ›

For Linux. Open a terminal and enter the following command: ssh @ . For example, if the IP address is 192.168. 99.118 and the username is "rancher", enter the command ssh rancher@192.168.99.118 .

How to connect to a Linux server with SSH? ›

For Linux. Open a terminal and enter the following command: ssh @ . For example, if the IP address is 192.168. 99.118 and the username is "rancher", enter the command ssh rancher@192.168.99.118 .

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 do I connect to a Windows server via SSH? ›

Open command prompt as administrator, e.g. with Windows search > “cmd.exe” > “run as administrator”. Enter CMD command ssh . Connect to the desired server with ssh name@server . If necessary, consider the port: default is port 22, change port with -pPortnumber behind the server name.

How to connect to remote server using SSH key? ›

All commands will be entered through the terminal.
  1. Step 1: Generate SSH Keys. Open the terminal on your local machine. ...
  2. Step 2: Name your SSH keys. ...
  3. Step 3: Enter a passphrase (optional) ...
  4. Step 4: Move the public key to the remote machine. ...
  5. Step 5: Test your connection.
Jan 8, 2017

How to connect Windows and Linux using SSH? ›

Connect to a Linux server via SSH
  1. Open the list of your servers and click on the one you need. Click the Instructions button. ...
  2. Open a terminal (for Linux) or a command line (for Windows) on your computer. Enter the command: ...
  3. The connection will prompt you for a password. Enter the password from the instructions.

What is SSH in Linux command? ›

SSH Command in Linux

The ssh command provides a secure encrypted connection between two hosts over an insecure network. This connection can also be used for terminal access, file transfers, and for tunneling other applications. Graphical X11 applications can also be run securely over SSH from a remote location.

How to login to a server in Linux? ›

Connect to a Linux server by using the system user and password.
  1. (Optional) Configure a logon password for the Linux server. ...
  2. Run the following command to connect to the Linux server: ssh root@<Public IP address of the Linux server> ...
  3. Enter yes and press the Enter key.
Jan 31, 2024

How to start SSH remotely? ›

SSH uses port 22 by default, but you can change this to a different port. 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.

How to enable SSH in Linux? ›

  1. Step1: Install and enable SSH Server. ...
  2. Step2: Enable SSH Protocol Version 2. ...
  3. Step 3: Customize the default SSH port (22) ...
  4. Step4: Disable root login (SSH) ...
  5. Step 5: Use ssh keys (Public and Private) ...
  6. Step 6: Disable X11 Forwarding. ...
  7. Step 7: Disable Empty Passwords. ...
  8. Step 8: Set Max Authentication Attempts.
Mar 17, 2023

What port to connect to SSH? ›

The default SSH port is 22.

How to config SSH in Windows? ›

To configure SSH on Windows:
  1. Install or enable SSH server on your Windows machine. ...
  2. To enable the built-in SSH server for older Windows versions, see Install Win32 OpenSSH.
  3. Configure and start your SSH server.
  4. If you have firewall, open the SSH port in your firewall.

How to set SSH port in Windows? ›

How to Change the SSH Server Port Number on Windows in 2022
  1. Click the Start button at the bottom left corner of your screen.
  2. Click RUN.
  3. Type REGEDIT.
  4. Click OK.
  5. Select Registry Key: ...
  6. Select the menu item Edit and then click on Modify.
  7. Enter the new value for the usGSWSSHDPort and click OK.

How do I connect 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 connect to a remote server in Windows? ›

On your local Windows PC: In the search box on the taskbar, type Remote Desktop Connection, and then select Remote Desktop Connection. In Remote Desktop Connection, type the name of the PC you want to connect to (from Step 1), and then select Connect.

How to login using SSH key in Linux? ›

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 to login to Linux server using SSH 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 to connect to Linux VM using SSH key? ›

To connect to the VM, execute the following command in the command line:
  1. ssh <username>@<VM_public_IP_address> Where <username> is the VM account username. ...
  2. ssh -i <key_path\key_file_name> <username>@<VM_public_IP_address> ...
  3. The authenticity of host '130.193.

How to open SSH server in Linux? ›

The procedure is as follows:
  1. Open the terminal application.
  2. You must log in as root.
  3. Use the following commands to start the sshd service: /etc/init.d/sshd start. OR (for modern Linux distro with systemd) ...
  4. In some cases, the actual script name is different. For example, it is ssh.service on a Debian/Ubuntu Linux.
Mar 31, 2024

How to connect to server using port SSH command? ›

How to connect to an SSH server using an alternate port
  1. Determine the port the SSH server uses. ...
  2. Check if the client host can reach the server's listening port (optional). ...
  3. Use the -p option to specify the port when connecting. ...
  4. Add the port directive to the SSH client configuration file for persistent connection option.

Top Articles
How Does Chlorine Affect Your Immune System? » The Candida Diet
Food Sensitivity and Allergies in Shiba Inus
Pinellas County Jail Mugshots 2023
Unity Stuck Reload Script Assemblies
How To Do A Springboard Attack In Wwe 2K22
PRISMA Technik 7-10 Baden-Württemberg
Barstool Sports Gif
Shariraye Update
2135 Royalton Road Columbia Station Oh 44028
Betonnen afdekplaten (schoorsteenplaten) ter voorkoming van lekkage schoorsteen. - HeBlad
Who called you from 6466062860 (+16466062860) ?
Buff Cookie Only Fans
Midlife Crisis F95Zone
Price Of Gas At Sam's
50 Shades Darker Movie 123Movies
Destiny 2 Salvage Activity (How to Complete, Rewards & Mission)
Foxy Brown 2025
Palm Springs Ca Craigslist
Optum Urgent Care - Nutley Photos
Jail View Sumter
Toothio Login
Urban Dictionary Fov
2011 Hyundai Sonata 2 4 Serpentine Belt Diagram
Craigslist Northern Minnesota
O'reilly's In Monroe Georgia
Everything You Need to Know About Ñ in Spanish | FluentU Spanish Blog
Myra's Floral Princeton Wv
Most popular Indian web series of 2022 (so far) as per IMDb: Rocket Boys, Panchayat, Mai in top 10
Shnvme Com
Toth Boer Goats
Trizzle Aarp
Search All of Craigslist: A Comprehensive Guide - First Republic Craigslist
Japanese Big Natural Boobs
Worcester County Circuit Court
Beaufort SC Mugshots
Ig Weekend Dow
Chathuram Movie Download
Stranahan Theater Dress Code
Walgreens On Secor And Alexis
Courses In Touch
Top 40 Minecraft mods to enhance your gaming experience
Tableaux, mobilier et objets d'art
Valls family wants to build a hotel near Versailles Restaurant
Random Animal Hybrid Generator Wheel
UT Announces Physician Assistant Medicine Program
9:00 A.m. Cdt
Matt Brickman Wikipedia
Motorcycles for Sale on Craigslist: The Ultimate Guide - First Republic Craigslist
Makemkv Key April 2023
Zadruga Elita 7 Live - Zadruga Elita 8 Uživo HD Emitirani Sat Putem Interneta
Research Tome Neltharus
Latest Posts
Article information

Author: Ms. Lucile Johns

Last Updated:

Views: 6289

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Ms. Lucile Johns

Birthday: 1999-11-16

Address: Suite 237 56046 Walsh Coves, West Enid, VT 46557

Phone: +59115435987187

Job: Education Supervisor

Hobby: Genealogy, Stone skipping, Skydiving, Nordic skating, Couponing, Coloring, Gardening

Introduction: My name is Ms. Lucile Johns, I am a successful, friendly, friendly, homely, adventurous, handsome, delightful person who loves writing and wants to share my knowledge and understanding with you.