Setting Up and Using SSH

SSH Series: Part 2
Posted by Munish Mehta on Wednesday, January 22, 2025
In this article i would be show you how to set up and use SSH to make our first secure connection.

This article is part of a series.

ssh Welcome back to our SSH series! In the previous instalment, I discussed the origins of SSH and why it replaced Telnet. Now, let’s roll up our sleeves and get hands-on. In this post, I’ll walk through installing SSH on various systems and outline basic commands you’ll use to connect and manage remote machines

Installing SSH

SSH on Linux

Most Linux distributions come with OpenSSH (both client and server) readily available in their default repositories.

Ubuntu/Debian

  • Install the ssh client (if not already installed):

    sudo apt-get update
    sudo apt-get install openssh-client
    
  • Install the server (to accept incoming connections):

    sudo apt-get update
    sudo apt-get install openssh-server
    
  • Check if SSH is running:

    sudo systemctl status ssh
    

    If it’s not active, start it:

    sudo systemctl enable ssh
    sudo systemctl start ssh
    

CentOS/RHEL

  • Install OpenSSH:

    sudo yum install openssh openssh-server
    
  • Enable and start the service:

    sudo systemctl enable sshd
    sudo systemctl start sshd
    
  • Check status:

    sudo systemctl status sshd
    

Once installed and running, your Linux server will listen on the default port 22 for SSH connections.

SSH on macOS

SSH Client is already installed on macOS by default. Just open Terminal and type:

ssh user@hostname

SSH on Windows

Modern Windows (Windows 10 and 11) can use the OpenSSH client that’s built in, or you can install PuTTY as an alternative.

Using the Built-In OpenSSH Client

Check if OpenSSH is installed
  • Open PowerShell or Command Prompt and type:

        ssh
    
  • If you see usage information, you have it installed. Otherwise, enable it:

    • Go to Settings -> Apps -> Optional features -> add a feature -> OpenSSH Client
Connecting
ssh user@remote-host

Using PuTTy

ssh
  • Download PuTTy and Install it
  • Launch:
    • Enter the hostname or IP of the remote server
    • Port: 22
    • Connection type: SSH
    • Click Open
  • Login:
    • If it’s your first time connecting, you’’ll see a security alert about the host key. Accept it if it matches your server’s key fingerprint

Basic SSH Commands

SSH is powerful but starts with a few core commands and options.

Connecting to a Server

The simplest command form:
bash ssh user@remote-host

Where
user: The username on the remote system
remote-host: This can be an IP address or a domain name (e.g.. 192.168.1.132 or example.com)

If your username on the local machine matches the remote username, you can sometimes omit user@

Common Command-Line Flags

  1. -p <port>: Connect to a non-standard port

    ssh -p 2222 user@remote-host
    
  2. -i <keyfile>: Specify a private key file for authentication

    ssh -i ~/.ssh/mykey user@remote-host
    
  3. -v: Increase verbosity (helpful for troubleshooting). You can stack like -vvv for more details

    ssh -v user@remote-host
    
  4. -L <local-port>:<host>:<remote-port>: Local port forwarding (Its a advanced topic. Let me know if you need more information on this topic)

  5. -N: Don’t execute a remote command; just forward ports (useful for tunnelling scenarios)

Key SSH Files and Directories

  1. ~/.ssh/ Folder This is your personal SSH directory within your home folder

    • Linux/MacOS: /home/<username>/.ssh/ or /Users/<username>/.ssh/
    • Windows (with OpenSSH): C:\Users\<username>\.ssh\ It stores:
    • Private/Public keys (e.g., id_rsa, id_rsa.pub)
    • Known_hosts (servers you’ve connected to)
    • Config file (for custom SSH settings)
  2. Authorized Keys File

    • Location: ~/.ssh/authorized_keys on the remote server
    • Purpose: Stores public keys of clients allowed to connect
    • If you set up key-based authentication on your server, you append your public key (.pub file) to this file
  3. Known Hosts file

    • Location: ~/.ssh/known_hosts on the client machine.
    • Purpose: Maintains host fingerprints for servers you’ve connected to, preventing man-in-the-middle attacks
    • When you connect to a server for the first time, SSH prompts you to accept its fingerprint, which is then stored here

Wrapping Up

By installing SSH and mastering these basic commands, you can securely connect to remote Linux, macOS, or Windows systems. SSH is a cornerstone of server administration and development workflows, enabling you to manage files, processes, and configurations from anywhere.

In the next part of SSH series, I’ll dive deeper into key-based authentication—a more secure and convenient method than using passwords. I’ll show you how to generate SSH keys, manage them, and disable password logins entirely.

If you have questions or want to share your experience with SSH, drop a comment below! I’d love to hear your thoughts as I continue exploring how machines secretly chat across the internet.

This article is part of a series.


comments powered by Disqus