Tool Logo
SSH Config File

How to Create and Use an SSH Config File

How to Create and Use an SSH Config File
2 min read
#SSH Config File

An SSH config file (~/.ssh/config, or C:\Users\YourUser\.ssh\config on Windows) saves connection settings for each server, so a short ssh myserver replaces a long command. Each Host block sets the server address, user, port and key:

Host myserver
    HostName 203.0.113.10
    User deploy
    Port 22
    IdentityFile ~/.ssh/id_ed25519

Below: creating the file on Windows and Linux, logging in with an alias, and using the same file for GitHub clone and pull.

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 [email protected]
    • 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