#!/bin/bash tailscale_status=$(tailscale status) # Extract the lines containing IP addresses and hostnames # Example lines we are interested in: # 100.101.102.103 server1 linux active; direct 192.168.1.101:41641, tx 3867808 rx 7391200 # 100.101.102.104 server2 windows active; direct 192.168.1.102:41641, tx 3867808 rx 7391200 ssh_entries=$(echo "$tailscale_status" | awk '/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ {print "Host " $2 "\n HostName " $1 "\n User alex\n"}') ssh_config_content="# SSH config - generated by tailscale script\n\n" ssh_config_content+="$ssh_entries" output_file="$HOME/.ssh/config" mkdir -p /root/.ssh echo -e "$ssh_config_content" > "$output_file" chmod 600 "$output_file" echo "SSH config file has been updated with Tailscale hosts at $output_file."