Shubham S Nimje logo
Shubham Nimje
SSH Config File

Create and Use the SSH Config File

Create and Use the SSH Config File
2 min read
#SSH Config File

Create and Use the SSH Config File

Enhance your SSH experience by leveraging the SSH config file! This guide walks you through creating the configuration file on Windows and Linux machines, defining aliases for easier server access, and utilizing it for streamlined Git operations.

To Ease Remote Server Login from a Windows Machine

  1. Create the SSH Config File

    • Open Notepad and save the file with the filename config at the path C:\Users\YourUser\.ssh.
    • Convert the newly created config text file to a config file:
      cd c:\users\yourUser\.ssh
      copy config.txt config
      del config.txt
  2. Edit the Config File

    • Open config using Notepad or Notepad++.

    • Add the following credentials, then save the file:

      Syntax:

      Host ANY_NAME_1
          HostName SERVER_IP or SERVER_DOMAIN
          User SERVER_USERNAME
          Port SERVER_PORT
          IdentityFile ~/.ssh/YOUR_PVT_SSH_KEY_NAME
          IdentitiesOnly yes

      Example:

      Host geek-vps-ubuntu
          HostName 181.219.74.228
          User rajesh
          Port 1037
          IdentityFile ~/.ssh/raj_ed25519
          IdentitiesOnly yes
    • You can add as many Host entries as needed to manage multiple servers and their respective SSH keys.

  3. Use the Config File

    • Now, you can use the Host alias to log in to the remote server via CMD or terminal:

      ssh HOST

      Example:

      ssh geek-vps-ubuntu

To Ease GitHub Clone and Pull Operations from a Linux Machine

  1. Access the Remote Server via SSH

    • Syntax: ssh -p PORT USERNAME@HOSTIP
    • Example: ssh -p 22 raj@216.32.44.12
    • OR
    • Syntax: ssh HOST
    • Example: ssh geek-vps-ubuntu
  2. Create the SSH Config File

    • Create the file:

      touch ~/.ssh/config
    • Edit the config file using nano:

      nano ~/.ssh/config
    • Add the following credentials, then save the file:

      Syntax:

      Host ANY_NAME_1
          HostName GITHUB_IP or GITHUB_DOMAIN
          User GITHUB_USERNAME
          IdentityFile ~/.ssh/YOUR_PVT_SSH_KEY_NAME
          IdentitiesOnly yes

      Example:

      Host react_project
          HostName github.com
          User geekyshow1
          IdentityFile ~/.ssh/react_ed25519
          IdentitiesOnly yes
    • You can add as many Host entries as needed to manage multiple GitHub repositories and their respective SSH keys.

  3. Use the Config File for Git Operations

    • Verify Connection:

      ssh -T git@HOST

      Example:

      ssh -T git@react_project
    • Clone Git Repo:

      git clone git@HOST:GITHUB_USERNAME/REPO_NAME

      Example:

      git clone git@react_project:geekyshow1/ecomm.git
    • Git Pull:

      git pull