BytePane

SSH Public Key Regex Pattern

Matches SSH public key format with algorithm prefix (rsa, ed25519, ecdsa) followed by Base64-encoded key data.

🔐
Security & Auth
Intermediate
Difficulty
Universal
Language
none
Flags
// Regular Expression
/^ssh-(rsa|ed25519|ecdsa)\s+[A-Za-z0-9+/=]+/

Live Regex Tester

Pattern Breakdown

^ssh-(rsa|ed25519|ecdsa)\s+[A-Za-z0-9+/=]+
Character class [ ]
Group ( )
Quantifier { }
Anchor ^ $
Repetition * + ?
Escape \
Alternation |
Any char .

Code Examples

JavaScript

const regex = /^ssh-(rsa|ed25519|ecdsa)\s+[A-Za-z0-9+/=]+/;
const test = "ssh-rsa AAAAB3NzaC1yc2EAAA...";
console.log(regex.test(test)); // true

// Extract matches
const matches = test.match(regex);
console.log(matches);

Python

import re

pattern = r'^ssh-(rsa|ed25519|ecdsa)\s+[A-Za-z0-9+/=]+'
test = "ssh-rsa AAAAB3NzaC1yc2EAAA..."
match = re.search(pattern, test)
print(match)  # Found!

Go

package main

import (
    "fmt"
    "regexp"
)

func main() {
    re := regexp.MustCompile(`^ssh-(rsa|ed25519|ecdsa)\s+[A-Za-z0-9+/=]+`)
    fmt.Println(re.MatchString("ssh-rsa AAAAB3NzaC1yc2EAAA...")) // true
}

Common Use Cases

SSH key managementserver configurationgit authentication

Match Examples

InputResult
ssh-rsa AAAAB3NzaC1yc2EAAA...Match
not-ssh-keyNo Match

About the SSH Public Key Regex

Matches SSH public key format with algorithm prefix (rsa, ed25519, ecdsa) followed by Base64-encoded key data.

Regular expressions (regex) are powerful pattern matching tools used across virtually all programming languages. The ssh public key pattern is classified as intermediate difficulty in the security & auth category. It works in all major programming languages.

When using this regex, always consider edge cases and test thoroughly with real-world data. Use the interactive tester above to validate the pattern against your specific inputs before deploying to production.

Need More Regex Patterns?

Browse our complete library of 100+ regex patterns with interactive testers.

Frequently Asked Questions

What is the SSH Public Key regex pattern?

Matches SSH public key format with algorithm prefix (rsa, ed25519, ecdsa) followed by Base64-encoded key data.

How do I use the SSH Public Key regex?

Use the pattern /^ssh-(rsa|ed25519|ecdsa)\s+[A-Za-z0-9+/=]+/ in your code. In JavaScript: new RegExp('^ssh-(rsa|ed25519|ecdsa)\s+[A-Za-z0-9+/=]+', ''). Test it above with your own input.

What does this SSH Public Key regex match?

This pattern matches: "ssh-rsa AAAAB3NzaC1yc2EAAA...". It does NOT match: "not-ssh-key". SSH key management, server configuration, git authentication.

Is the SSH Public Key regex beginner-friendly?

This pattern is rated Intermediate. It uses some advanced features like character classes and quantifiers.

What languages support the SSH Public Key regex?

This pattern works in all major programming languages including JavaScript, Python, Java, C#, Go, Ruby, PHP, and more. Syntax may vary slightly between regex engines.

Can I modify the SSH Public Key regex for my use case?

Yes! Use the interactive tester above to modify the pattern and test with your own data. Common modifications include making it case-insensitive (add 'i' flag), matching globally (add 'g' flag), or adjusting character classes.

Related Tools