SSH Config to /etc/hosts Converter

Convert OpenSSH client configuration files (~/.ssh/config) into local /etc/hosts or Windows hosts file mappings instantly.

How to Convert SSH Config to /etc/hosts

1

Paste SSH Config

Paste your ~/.ssh/config file containing Host and HostName declarations.

2

Extract Host Aliases

Click "Convert to /etc/hosts Format" to parse IP addresses and map all declared host aliases.

3

Append to Local Hosts

Copy or download the output and append it to /etc/hosts (Linux/macOS) or C:\Windows\System32\drivers\etc\hosts (Windows).

Tool Options

Multiple Alias Mapping

Supports multi-alias host lines (e.g. Host app app.internal) mapping multiple hostnames to a single target IP.

Clean Column Alignment

Formats output with fixed-width space padding for clean readability in system network files.

Private & Client-Side

All parsing logic executes 100% in your browser. Your internal IP addresses and host names are never transmitted or logged.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the SSH Config to /etc/hosts Converter do?

The SSH Config to /etc/hosts Converter parses OpenSSH client configuration files (~/.ssh/config) and extracts Host aliases and HostName destinations (IP addresses or domains). It generates structured, fixed-width mapped lines ready to append directly into /etc/hosts (Linux/macOS) or C:\Windows\System32\drivers\etc\hosts (Windows).

Core Concepts

Understanding SSH config to /etc/hosts mapping:

  • Host & HostName Pairing: Maps each target IP address from HostName to all declared Host alias nicknames on the same line.
  • Multiple Alias Support: Automatically extracts multi-alias declarations (e.g. Host db db.internal db.local) into a single consolidated line.
  • Column Padding: Formats output with 20-character column spacing for clean visual alignment in system network hosts files.

How to use the tool?

  1. Paste SSH Config: Paste your ~/.ssh/config file content into the editor or click Load Sample Config.
  2. Execute Conversion: Click Convert to /etc/hosts Format to extract host mapping entries.
  3. Copy & Apply: Click Copy or Download, then append the output to /etc/hosts or your system hosts file.

Related Developer Utilities

If you work with SSH configurations, networking, and server provisioning, explore these complementary tools:

REST API Integration

Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/ssh/ssh-config-to-hosts) to programmatically convert OpenSSH client configuration (~/.ssh/config) files into /etc/hosts mapping definitions.

API Request Parameters

Name Type Description Example
rawText String The ~/.ssh/config file content string to parse. "Host prod-db\n HostName 10.0.1.50"

API Request Payload Examples

cURL

curl -X POST https://blueutils.com/api/ssh/ssh-config-to-hosts \
  -H "Content-Type: application/json" \
  -d '{
    "rawText": "Host prod-db\n  HostName 10.0.1.50\n  User ubuntu\n\nHost web-staging\n  HostName 192.168.1.100"
  }'

Python

import requests

url = "https://blueutils.com/api/ssh/ssh-config-to-hosts"
payload = {
    "rawText": "Host prod-db\n  HostName 10.0.1.50\n  User ubuntu\n\nHost web-staging\n  HostName 192.168.1.100"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String jsonPayload = """
            {
                "rawText": "Host prod-db\\n  HostName 10.0.1.50\\n  User ubuntu\\n\\nHost web-staging\\n  HostName 192.168.1.100"
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/ssh/ssh-config-to-hosts"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

API Response Parameters

Name Type Description Example
isValid Boolean Indicates whether conversion succeeded. true
convertedCount Number Count of valid mapped host entries. 2
converted String Formatted /etc/hosts file content string. "10.0.1.50 prod-db\n..."

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "convertedCount": 2,
  "converted": "# Generated from ~/.ssh/config via Blueutils\n# Format: <IP_OR_TARGET> <HOST_ALIAS>\n10.0.1.50            prod-db\n192.168.1.100        web-staging"
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "No valid Host blocks with a \"HostName\" directive were found in the SSH config."
}

Rate Limit Exceeded Response (HTTP 429 Too Many Requests)

{
  "error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}

Why use an API to convert SSH config to /etc/hosts?

Integrating the SSH Config to /etc/hosts API into DevOps provisioning scripts, devcontainers, or AI agent tool calling provides key benefits:

  • Rapid Script Validation: Generates local DNS aliases for ephemeral VM clusters and dev containers automatically.
  • Optimized Token Efficiency for AI Agents: LLMs frequently mix up multi-alias column alignment. Calling the API extracts IP-hostname pairs deterministically without token consumption.
  • Deterministic Accuracy Without Hallucinations: Ensures 100% accurate column alignment and syntax formatting for system network configuration.

Native Usage

How to convert SSH configs to /etc/hosts locally in terminal environments or scripts:

Windows (CMD / PowerShell)

# Extract Host and HostName from ~/.ssh/config in PowerShell
$configPath = "$env:USERPROFILE\.ssh\config"
if (Test-Path $configPath) {
    Get-Content $configPath | ForEach-Object {
        if ($_ -match '^\s*Host\s+([^\*]+)$') { $h = $matches[1].Trim() }
        elseif ($_ -match '^\s*HostName\s+(\S+)' -and $h) {
            Write-Output "$($matches[1].Trim().PadRight(20)) $h"
            $h = ""
        }
    }
}

Linux / Unix (Bash)

# Parse ~/.ssh/config using awk in Linux
awk '
  tolower($1) == "host" && $2 != "*" { host = $2 }
  tolower($1) == "hostname" && host != "" {
    printf "%-20s %s\n", $2, host
    host = ""
  }
' ~/.ssh/config

Python

Using Python:

import re

with open("~/.ssh/config".replace("~", "/home/user")) as f:
    content = f.read()

for match in re.finditer(r'Host\s+([^\n]+)\n\s+HostName\s+([^\n]+)', content):
    aliases = match.group(1).strip()
    ip = match.group(2).strip()
    print(f"{ip:<20} {aliases}")

Java

Using Java:

import java.nio.file.*;
import java.util.List;

public class SshToHostsExample {
    public static void main(String[] args) throws Exception {
        List<String> lines = Files.readAllLines(Paths.get(System.getProperty("user.home"), ".ssh", "config"));
        String host = "";
        for (String line : lines) {
            String trimmed = line.trim();
            if (trimmed.startsWith("Host ") && !trimmed.contains("*")) {
                host = trimmed.substring(5).trim();
            } else if (trimmed.startsWith("HostName ") && !host.isEmpty()) {
                String ip = trimmed.substring(9).trim();
                System.out.printf("%-20s %s%n", ip, host);
                host = "";
            }
        }
    }
}

Frequently Asked Questions (FAQ)

How do I convert ~/.ssh/config to /etc/hosts?

Paste your SSH config into the tool and click Convert to /etc/hosts Format. The tool maps each HostName to all associated Host aliases.

Does it support multiple host aliases on a single line?

Yes. Multi-alias declarations (e.g. Host db db.local) map all aliases next to the target IP address.

Are IP addresses transmitted to remote servers?

No. All parsing runs 100% client-side in your browser, keeping your internal network topology private.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.