Step-by-Step Guide: Connecting to a Remote Server on CentOS Using SSH
What is SSH ?
SSH, or Secure Shell, constitutes a cryptographic network protocol designed to enable secure communication between two systems over networks that may not be secure.
This protocol is widely employed for remote access to servers and the secure transmission of files between computers.
In essence, SSH acts as a secure conduit, establishing a confidential channel for communication in scenarios where the network may pose security risks.
This technology is instrumental for professionals seeking a reliable and secure method of managing servers and transferring sensitive data across computers in a controlled and protected manner. ssh runs at TCP/IP port 22.
Syntax of SSH Command in Linux
The basic syntax for using the SSH command is as follows:
ssh [username]@[hostname or IP address]
Here,
Replace [username]
with your remote server username, and [hostname or IP address]
with the server’s hostname or IP address.
How to Use SSH to Connect to a Remote Server in Linux
To connect to a remote server using SSH in CentOS (or any Linux distribution), you need the following:
SSH Client: Installed on your local machine (usually pre-installed on most Linux distributions).
Remote Server: An SSH server running on the remote machine.
Login Credentials: Typically, a username and password or a private key if key-based authentication is enabled.
Prerequisites :
Before delving into the world of SSH, it’s essential to ensure that certain prerequisites are in place. Here’s a checklist to guarantee a smooth connection:
Remote Computer Status:
- Make sure the remote computer is turned on and has an active network connection. SSH relies on network connectivity, and the remote server needs to be accessible.
Identification Information:
- Obtain the IP address or the name of the remote machine. This information is crucial for directing your SSH connection to the correct server.
Permission to Access:
- Ensure that you have the necessary permissions to access the remote computer. This typically involves having a valid username and password for the remote server.
Firewall Settings:
- Check the firewall settings on both your local machine and the remote server. SSH connections use a specific port (usually port 22), so it’s crucial to ensure that your firewall allows SSH traffic. Adjustments may be required to permit secure communication.
Steps to Connect to a Remote Server using SSH:
Open a Terminal: This is where you will issue SSH commands.
Basic SSH Command Structure:
ssh username@remote_server_ip
username: Your username on the remote server.
remote_server_ip: The IP address or hostname of the remote server.
Example Command:
ssh aditya@192.168.1.100
In this case, replace aditya with your username and 192.168.1.100 with the remote server's IP address.
Password Authentication: If password-based authentication is used, after executing the SSH command, you will be prompted to enter the password for the specified user. Simply type your password and press Enter.
Key-Based Authentication (Optional but more secure): If key-based authentication is set up, you can connect using the private key:
ssh -i /path/to/private_key username@remote_server_ip
Here,
-i
specifies the path to the private key file.
Options available in ssh
Note: Here instead of user and host add username and IP address you want to connect to. And localhost is IP of our local system.
Options | Description | Syntax |
-1 | Forces ssh to use protocol SSH-1 only. | ssh -1 user@host |
-2 | Forces ssh to use protocol SSH-2 only. | ssh -2 user@host |
-4 | Allows IPv4 addresses only. | ssh -4 user@host |
-6 | Allows IPv6 addresses only. | ssh -6 user@host |
-A | Authentication agent connection forwarding is enabled. | ssh -A user@host |
-a | Authentication agent connection forwarding is disabled. | ssh -a user@host |
-C | Compresses all data (including stdin, stdout, stderr, and data for forwarded X11 and TCP connections) for a faster transfer of data. | ssh -C user@host |
-c | Selects the cipher specification for encrypting the session. Specific cipher algorithm will be selected only if both the client and the server support it. | ssh -c aes256-cbc user@host |
-f | Requests ssh to go to background just before command execution. | ssh -f user@host command |
-g | Allows remote hosts to connect to local forwarded ports. | ssh -g -L 8080:localhost:80 user@host |
-n | Prevents reading from stdin. | ssh -n user@host command |
-p | Port to connect to on the remote host. | ssh -p 2222 user@host |
-q | Suppresses all errors and warnings | ssh -q user@host |
-V | Display the version number. | ssh -V |
-v | Verbose mode. It echoes everything it is doing while establishing a connection. It is very useful in the debugging of connection failures. | ssh -v user@host |
-X | Enables X11 forwarding (GUI Forwarding). | ssh -X user@host |
The Three Major Encryption Techniques Used by SSH.
SSH is significantly more secure than the other protocols such as telnet because of the encryption of the data. There are three major encryption techniques used by SSH:
Symmetrical encryption: This encryption works on the principle of the generation of a single key for encrypting as well as decrypting the data. The secret key generated is distributed among the clients and the hosts for a secure connection. Symmetrical encryption is the most basic encryption and performs best when data is encrypted and decrypted on a single machine.
Asymmetrical encryption: This encryption is more secure because it generates two different keys: Public and Private key. A public key is distributed to different host machines while the private key is kept securely on the client machine. A secure connection is established using this public-private key pair.
Hashing: One-way hashing is an authentication technique which ensures that the received data is unaltered and comes from a genuine sender. A hash function is used to generate a hash code from the data. It is impossible to regenerate the data from the hash value. The hash value is calculated at the sender as well as the receiver’s end. If the hash values match, the data is authentic.
Advantages Of SSH:
Strong encryption and authentication mechanisms.
Secure remote access and file transfer.
Customizable with port forwarding and tunneling capabilities.
Cross-platform support and flexibility.
Disadvantages Od SSH:
Can be complex for beginners.
Improper configuration can expose security vulnerabilities.
Slower file transfer compared to non-encrypted methods.
Dependent on a stable network connection.
Uses Of SSH:
Remote system administration
file transfer
automated tasks
secure tunneling
Git version control
secure communication.
Conclusion
In this article we discussed Secure Shell (SSH) which is like a secret, safe tunnel for computers to talk securely over the internet. This guide is for beginners, helping them use SSH to connect their computer to faraway servers in the Linux world. It covers everything from the basic SSH command to prerequisites like checking your internet connection and having the right permissions. You’ll learn how to install SSH on Linux, create secure keys, and use them for safer logins
Subscribe to my newsletter
Read articles from Aditya Gadhave directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Aditya Gadhave
Aditya Gadhave
👋 Hello! I'm Aditya Gadhave, an enthusiastic Computer Engineering Undergraduate Student. My passion for technology has led me on an exciting journey where I'm honing my skills and making meaningful contributions.