SSH2 public key (RFC 4716) (.pub)
.pub file signature | application/octet-stream
SSH2 public key (RFC 4716) is a text-based public key file format defined by the IETF for exchanging SSH public keys. It is used to distribute and import public keys for SSH authentication, account setup, and key management across clients and servers. The format contains only public key material and is generally safe to share, though it is a legacy interchange format that has been largely superseded by OpenSSH key conventions.
Magic Bytes
Offset 0
2D 2D 2D 2D 2D 42 45 47 49 4E 20 53 53 48 32 20 4B 45 59 2D 2D 2D 2D 2D
Sources: Wikipedia
All Known Signatures
3 signature variants are documented for .pub files across multiple sources.
| Hex Signature | Offset | Sources |
|---|---|---|
| 2D 2D 2D 2D 2D 42 45 47 49 4E 20 53 53 48 32 20 4B 45 59 2D 2D 2D 2D 2D | 0 | Wikipedia |
| D0 CF 11 E0 A1 B1 1A E1 | 0 | Gary Kessler |
| FD FF FF FF 02 | 512 | Gary Kessler |
Extension
.pub
MIME Type
application/octet-stream
Byte Offset
0
Risk Level
Safe
Validation Code
How to validate .pub files in Python
def is_pub(file_path: str) -> bool:
"""Check if file is a valid PUB by magic bytes."""
signature = bytes([0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x53, 0x53, 0x48, 0x32, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D])
with open(file_path, "rb") as f:
return f.read(24) == signature
How to validate .pub files in Node.js
function isPUB(buffer: Buffer): boolean {
const signature = Buffer.from([0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x53, 0x53, 0x48, 0x32, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D]);
return buffer.subarray(0, 24).equals(signature);
}
How to validate .pub files in Go
func IsPUB(data []byte) bool {
signature := []byte{0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x53, 0x53, 0x48, 0x32, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D}
if len(data) < 24 {
return false
}
return bytes.Equal(data[:24], signature)
}
API Endpoint
/api/v1/pub
curl https://filesignature.org/api/v1/pub
See the full API documentation for all endpoints and parameters.
Related Formats
Frequently Asked Questions
What is a .pub file?
A .pub file is a SSH2 public key (RFC 4716) file. SSH2 public key (RFC 4716) is a text-based public key file format defined by the IETF for exchanging SSH public keys. It is used to distribute and import public keys for SSH authentication, account setup, and key management across clients and servers. The format contains only public key material and is generally safe to share, though it is a legacy interchange format that has been largely superseded by OpenSSH key conventions.
What are the magic bytes for .pub files?
The magic bytes for SSH2 public key (RFC 4716) files are 2D 2D 2D 2D 2D 42 45 47 49 4E 20 53 53 48 32 20 4B 45 59 2D 2D 2D 2D 2D at byte offset 0. These bytes uniquely identify the file format regardless of the file extension.
How do I validate a .pub file?
To validate a .pub file, read the first bytes of the file and compare them against the known magic bytes (2D 2D 2D 2D 2D 42 45 47 49 4E 20 53 53 48 32 20 4B 45 59 2D 2D 2D 2D 2D) at offset 0. This is more reliable than checking the file extension alone, as extensions can be renamed.
What is the MIME type for .pub files?
There is no officially registered MIME type for .pub files. Systems typically use application/octet-stream as a generic fallback when handling this format.
Is it safe to open .pub files?
SSH2 public key (RFC 4716) (.pub) files are generally safe to open. They are classified as low risk because they primarily contain data rather than executable code. However, always ensure files come from a trusted source.