How to Connect to Your Server with Terminal

Connecting to a server via the terminal is an essential skill for system administrators, developers, and anyone managing remote systems. This guide will walk you through different methods to connect to your server using SSH and other protocols.

Step 1: Ensure SSH is Installed

Most Linux servers support SSH (Secure Shell) for remote access. To check if SSH is installed on your local machine, run:

ssh -V

If SSH is not installed, install it using:

  • Ubuntu/Debian/Linux Mint: sudo apt install openssh-client -y
  • CentOS/RHEL: sudo yum install openssh-clients -y

Step 2: Find Your Server’s IP Address

To connect, you need your server’s IP address or domain name. If you don’t know your server’s IP, check it using:

ip a

or contact your hosting provider.

Step 3: Connect to Your Server Using SSH

Use the following command to establish a connection:

ssh username@your-server-ip

For example:

ssh root@192.168.1.100

If prompted, type yes to accept the connection, then enter your password.

Step 4: Connect with an SSH Key (Recommended)

Using SSH keys is more secure than passwords. To generate an SSH key pair, run:

ssh-keygen -t rsa -b 4096

Then copy your public key to the server:

ssh-copy-id username@your-server-ip

Now, you can connect without entering a password:

ssh username@your-server-ip

Step 5: Connect Using a Custom Port

If your server uses a non-default SSH port, specify it using the -p flag:

ssh -p 2222 username@your-server-ip

Step 6: Connect Using SCP or SFTP for File Transfers

To copy files to your server using SCP:

scp file.txt username@your-server-ip:/home/username/

For an interactive SFTP session:

sftp username@your-server-ip

Step 7: Disconnect from the Server

To disconnect from the SSH session, type:

exit

or press Ctrl + D.

Troubleshooting Connection Issues

  • Connection Refused: Ensure the SSH service is running on the server: sudo systemctl status ssh
  • Permission Denied: Verify your username, password, or SSH key permissions.
  • Firewall Blocks SSH: Allow SSH traffic with: sudo ufw allow ssh