SSH authorized_keys Option & Restriction Generator

Configure OpenSSH ~/.ssh/authorized_keys security restrictions, forced commands, IP whitelists, and port-forwarding locks without syntax errors.

Executes exclusively whenever this key connects.
Comma-separated IP addresses, CIDR blocks, or domains.

How to Restrict SSH Keys in authorized_keys

1

Paste Public Key

Paste your OpenSSH public key (e.g. from ~/.ssh/id_ed25519.pub) into the editor.

2

Configure Access Restrictions

Specify a forced command, whitelist allowable source IP addresses or subnets, and toggle forwarding locks.

3

Copy & Deploy

Copy the restricted one-line entry or execute the one-line installer command on your target Linux server.

Tool Options

Forced Command Execution

Locks the key to a single executable (e.g. rsync --server or backup scripts), preventing arbitrary shell commands.

IP & CIDR Whitelisting

Applies from="..." clauses to reject connection attempts originating outside designated VPN or bastion IPs.

Forwarding & PTY Locks

Disables interactive terminal allocation (no-pty) and prevents unauthorized SSH tunneling or agent hijackings.

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 authorized_keys Option & Restriction Generator do?

The SSH authorized_keys Option & Restriction Generator allows system administrators, DevOps engineers, and security teams to construct hardened OpenSSH ~/.ssh/authorized_keys lines with granular access controls. It formats forced commands (command="..."), source IP/CIDR subnet whitelists (from="..."), environment variable injections, and security flags (no-pty, no-port-forwarding, no-agent-forwarding, no-X11-forwarding) without syntax errors or invalid whitespace.

Core Concepts

Understanding OpenSSH key restriction parameters in authorized_keys:

  • Forced Commands (command="..."): Restricts the public key strictly to executing a specific script or binary (such as rsync --server or automated CI deployment tasks). Any command supplied by the client is ignored and stored in $SSH_ORIGINAL_COMMAND.
  • Source IP Whitelisting (from="..."): Rejects connection attempts unless originating from designated static IP addresses, CIDR ranges (e.g. 192.168.1.0/24), or wildcard hostnames (*.corp.internal).
  • TTY & Tunneling Hardening: Flags like no-pty prevent interactive shell allocations, while no-port-forwarding and no-agent-forwarding prevent unauthorized network pivots and SSH agent credential theft.

How to use the tool?

  1. Paste Public Key: Paste your OpenSSH public key string (e.g. ssh-ed25519 AAAAC3Nza... user@workstation) or click Load Sample.
  2. Configure Security Options: Specify forced command paths, source IP addresses/CIDRs, environment variables, and toggle security hardening checkboxes.
  3. Generate & Install: Click Generate authorized_keys Line to copy the formatted line or execute the one-line server installer script.

Related Developer Utilities

If you work with SSH keys, server access, and Linux security, explore these complementary tools:

REST API Integration

Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/ssh/authorized-keys-generator) to programmatically generate restricted authorized_keys lines and server installation commands.

API Request Parameters

Name Type Description Example
rawText String Raw OpenSSH public key string. "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5... user@host"
options.command String Forced command to execute. "/usr/local/bin/backup.sh"
options.from String Comma-separated IP addresses or CIDRs. "192.168.1.0/24,10.0.0.5"
options.environment String Environment variable string (NAME=val). "BACKUP_ENV=prod"
options.noPty Boolean Disable TTY allocation (no-pty). Default: true. true
options.noPortForwarding Boolean Disable port forwarding (no-port-forwarding). Default: true. true
options.noAgentForwarding Boolean Disable agent forwarding (no-agent-forwarding). Default: true. true
options.noX11Forwarding Boolean Disable X11 forwarding (no-X11-forwarding). Default: true. true

API Request Payload Examples

cURL

curl -X POST https://blueutils.com/api/ssh/authorized-keys-generator \
  -H "Content-Type: application/json" \
  -d '{
    "rawText": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGt7X2N+h4l7T5rL6H3n8P9Z1m+2q4w6e8r0t2y4u6i8 deployer@ci",
    "options": {
      "command": "/usr/local/bin/ci-deploy.sh",
      "from": "10.0.0.0/16",
      "noPty": true,
      "noPortForwarding": true
    }
  }'

Python

import requests

url = "https://blueutils.com/api/ssh/authorized-keys-generator"
payload = {
    "rawText": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGt7X2N+h4l7T5rL6H3n8P9Z1m+2q4w6e8r0t2y4u6i8 deployer@ci",
    "options": {
        "command": "/usr/local/bin/ci-deploy.sh",
        "from": "10.0.0.0/16",
        "noPty": True
    }
}
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": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGt7X2N+h4l7T5rL6H3n8P9Z1m+2q4w6e8r0t2y4u6i8 deployer@ci",
                "options": {
                    "noPty": true,
                    "noPortForwarding": true
                }
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/ssh/authorized-keys-generator"))
            .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 formatting succeeded. true
optionsPrefix String Formatted comma-separated options prefix string. "command=\"...\",no-pty"
keyType String Detected public key type. "ssh-ed25519"
authorizedKeyLine String Complete one-line restricted authorized_keys string. "no-pty ssh-ed25519 ..."
installCommand String One-line shell command to safely append key with permissions. "mkdir -p ~/.ssh && ..."

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "optionsPrefix": "command=\"/usr/local/bin/ci-deploy.sh\",from=\"10.0.0.0/16\",no-pty,no-port-forwarding",
  "keyType": "ssh-ed25519",
  "comment": "deployer@ci",
  "authorizedKeyLine": "command=\"/usr/local/bin/ci-deploy.sh\",from=\"10.0.0.0/16\",no-pty,no-port-forwarding ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGt7X2N+h4l7T5rL6H3n8P9Z1m+2q4w6e8r0t2y4u6i8 deployer@ci",
  "installCommand": "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo \"command=\\\"/usr/local/bin/ci-deploy.sh\\\",from=\\\"10.0.0.0/16\\\",no-pty,no-port-forwarding ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGt7X2N+h4l7T5rL6H3n8P9Z1m+2q4w6e8r0t2y4u6i8 deployer@ci\" >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "Invalid SSH public key. Expected format: [options] <key-type> <base64-blob> [comment]"
}

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 generate restricted authorized_keys lines?

Integrating the SSH authorized_keys Generator API into server provisioning scripts, CI/CD runners, or AI agent tool calling provides key benefits:

  • Automated Server Hardening: Dynamically generates restricted authorized_keys lines for ephemeral deployment keys without manual string formatting errors.
  • Optimized Token Efficiency for AI Agents: LLMs frequently inject invalid spaces into OpenSSH option strings, which invalidates the key on the server. Calling the API formats option tokens deterministically.
  • Deterministic Security Safeguards: Ensures proper comma separation, quote escaping, and correct Unix permission commands (chmod 700 / 600).

Native Usage

How to manage and test authorized_keys restrictions natively:

Linux / Unix (Bash)

# Add restricted key line manually to authorized_keys
mkdir -p ~/.ssh && chmod 700 ~/.ssh
echo 'command="/usr/local/bin/backup.sh",no-pty ssh-ed25519 AAAAC3NzaC... backup@bot' >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

# Test SSH connection with verbose output
ssh -v -i ~/.ssh/id_ed25519 user@server

Windows (PowerShell)

# Create .ssh directory with restricted permissions on Windows OpenSSH Server
$sshDir = "$HOME\.ssh"
if (!(Test-Path $sshDir)) { New-Item -ItemType Directory -Path $sshDir | Out-Null }

$keyLine = 'command="/usr/local/bin/backup.sh",no-pty ssh-ed25519 AAAAC3NzaC... backup@bot'
Add-Content -Path "$sshDir\authorized_keys" -Value $keyLine -Encoding utf8

# Set strict ACL permissions (Windows equivalent of chmod 600)
icacls "$sshDir\authorized_keys" /inheritance:r /grant "$($env:USERNAME):(R,W)"

Windows (Command Prompt)

:: Append restricted key to authorized_keys
if not exist "%USERPROFILE%\.ssh" mkdir "%USERPROFILE%\.ssh"
echo command="/usr/local/bin/backup.sh",no-pty ssh-ed25519 AAAAC3NzaC... backup@bot >> "%USERPROFILE%\.ssh\authorized_keys"

:: Test connection
ssh -v -i "%USERPROFILE%\.ssh\id_ed25519" user@server

Python

Using Python:

def format_authorized_key(pubkey, command=None, from_ip=None, no_pty=True):
    opts = []
    if command: opts.append(f'command="{command}"')
    if from_ip: opts.append(f'from="{from_ip}"')
    if no_pty: opts.append('no-pty')
    prefix = ",".join(opts)
    return f"{prefix} {pubkey}".strip()

print(format_authorized_key("ssh-ed25519 AAAAC3Nza... user@work", command="/app/sync.sh", from_ip="10.0.0.1"))

Java

Using Java:

public class AuthorizedKeysExample {
    public static void main(String[] args) {
        String key = "ssh-ed25519 AAAAC3Nza... user@work";
        String options = "command=\"/app/sync.sh\",no-pty";
        System.out.println(options + " " + key);
    }
}

Frequently Asked Questions (FAQ)

How do I add restrictions to an SSH authorized_keys line?

Paste your OpenSSH public key into the tool, configure restrictions such as command="...", from="...", or no-pty, and click Generate authorized_keys Line. The tool formats the exact option prefix without syntax errors.

What does the no-pty option do?

no-pty prevents the client from requesting a pseudo-terminal (interactive TTY shell). This is essential for restricting automated CI/CD deployment or backup keys.

How do I apply the generated line to my server?

You can append the line to ~/.ssh/authorized_keys on your remote server or run the provided one-line script which automatically ensures correct chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys permissions.

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.