How to SSH a remote server via terminal?

From PheonixSolutions
Jump to navigation Jump to search

How to SSH a remote server via Terminal

Introduction

SSH, or Secure Shell, is a cryptographic network protocol that provides a secure way to access and manage network devices and servers over an unsecured network. It is widely used for securely connecting to remote systems, executing commands, and transferring files.

Prerequisites

  1. IP address or hostname of the remote server

  2. Username

  3. Password or SSH key -You need either the password associated with the username or an SSH key pair for authentication.

  4. Port number required only for pointing to other ports or other wise the server automatically assumes the default port is 22.

Implementation :

1. Without port number (Default port 22):

For-password-authentication: open-your-terminalcommand-line-and-run-the-following-command

  ssh username@ip_address_or_hostname

Replace “username” with your actual username, and “ip_address_or_hostname” with the IP address or hostname of your remote server.

Press Enter.

If the connection is successful, you should now be logged into the remote server via SSH.


2. For Key-Based Authentication:

Open your Terminal and use the following command

  ssh -i /path/to/private_key username@ip_address_or_hostname

Replace “/path/to/private_key” with the actual path/folders to your private key file, “username” with your actual username, and “ip_address_or_hostname” with the IP address or hostname of the remote server.

Press Enter.

If the connection is successful, you should now be logged into the remote server via SSH.


3. With port number (server configured ssh point with some other port):

For Password Authentication:

[edit]

Open your Terminal and use the following command

  ssh username@ip_address_or_hostname -p <portnumber>

Replace “username” with your actual username, and “ip_address_or_hostname” with the IP address or hostname of the remote server.Replace <port number> with actual pointing port number.

Press Enter.

If the connection is successful, you should now be logged into the remote server via SSH.

For Key-Based Authentication:

[edit]

Open your Terminal and use the following command

  ssh -i /path/to/private_key username@ip_address_or_hostname -p <port number>

Replace “/path/to/private_key” with the actual path/folders to your private key file, “username” with your actual username, and “ip_address_or_hostname” with the IP address or hostname of the remote server. Replace <port number> with the actual pointing port number.

Press Enter.

If the connection is successful, you should now be logged into the remote server via SSH.