Thursday, February 02, 2023

ssh into remote server easily

 Write a script that modifies the ~/.ssh/config file on Mac OS to set the Host to myhost, Hostname to dummy IP and User to deploy


Here is a script in Bash that modifies the ~/.ssh/config file on Mac OS to set the Host to myhost, Hostname to a dummy IP address and User to deploy:


#!/bin/bash


# Variables for the SSH configuration

host=myhost

hostname=<dummy_ip>

username=deploy


# Create or modify the SSH configuration file

echo "Host $host

  HostName $hostname

  User $username" >> ~/.ssh/config


Replace the placeholder <dummy_ip> with the desired dummy IP address. Then, save the script to a file and make it executable with the chmod +x command. You can then run the script from the terminal.


This script adds the desired SSH configuration to the ~/.ssh/config file on the Mac OS laptop. If the file does not exist, it will be created. If the Host entry already exists, the script will append the new configuration to the end of the file.