What Is SSH Key Authentication?
Graphic showing SSH key authentication: a private key kept on the user's device and a public key on the server used to create a secure, passwordless encrypted channel between them.
Understanding the Foundation of Secure Remote Access
In today's interconnected digital landscape, securing access to remote servers and systems has become more critical than ever. Every day, millions of authentication attempts occur across networks worldwide, with malicious actors constantly probing for vulnerabilities. Traditional password-based authentication, once considered sufficient, now represents a significant security risk in an era where brute-force attacks and credential theft have become increasingly sophisticated. The need for a more robust, reliable authentication method has never been more pressing for developers, system administrators, and organizations managing critical infrastructure.
SSH key authentication is a cryptographic method that allows users to access remote systems without transmitting passwords over the network. Rather than relying on something you know (a password), this approach uses a pair of mathematically linked cryptographic keys to verify identity. This article explores multiple perspectives on SSH key authentication—from technical implementation to security considerations, from practical deployment scenarios to common troubleshooting approaches—providing a comprehensive understanding of this essential technology.
Throughout this exploration, you'll gain practical knowledge about how SSH keys work at a fundamental level, learn the step-by-step process of generating and deploying them, understand the security advantages they provide over traditional methods, and discover best practices for managing keys in both personal and enterprise environments. Whether you're a developer setting up your first cloud server or an IT professional managing infrastructure at scale, this guide will equip you with the knowledge to implement SSH key authentication effectively and securely.
The Cryptographic Foundation of SSH Keys
SSH key authentication relies on public-key cryptography, also known as asymmetric cryptography. This mathematical framework uses two distinct but mathematically related keys: a public key that can be freely shared and a private key that must remain confidential. The elegance of this system lies in its one-way mathematical relationship—data encrypted with the public key can only be decrypted with the corresponding private key, and vice versa.
When you generate an SSH key pair, cryptographic algorithms create these two keys simultaneously. The most commonly used algorithms include RSA (Rivest-Shamir-Adleman), Ed25519 (Edwards-curve Digital Signature Algorithm), ECDSA (Elliptic Curve Digital Signature Algorithm), and DSA (Digital Signature Algorithm). Each algorithm offers different trade-offs between security strength, computational efficiency, and compatibility with various systems.
"The mathematical relationship between public and private keys creates a security foundation that's exponentially stronger than password-based systems, making brute-force attacks computationally infeasible."
The authentication process begins when you attempt to connect to a remote server. Your SSH client announces which public key it wants to use for authentication. The server checks whether this public key exists in its authorized keys list. If found, the server generates a random challenge message, encrypts it with your public key, and sends it back to your client. Your client then uses the private key to decrypt this challenge and sends the decrypted result back to the server. If the decrypted message matches what the server originally sent, authentication succeeds—proving you possess the private key without ever transmitting it across the network.
Key Generation Algorithms and Their Characteristics
Different cryptographic algorithms provide varying levels of security and performance. RSA keys have been the standard for decades, with 2048-bit keys considered the minimum acceptable length today, though 4096-bit keys are increasingly recommended. RSA's widespread compatibility makes it a safe choice for systems that need to work across diverse infrastructure.
Ed25519 keys represent the modern standard, offering equivalent security to 3072-bit RSA keys while being significantly smaller (256 bits) and faster to generate and use. This algorithm is based on elliptic curve cryptography and provides excellent performance with strong security guarantees. However, some older systems may not support Ed25519, which can limit its applicability in legacy environments.
ECDSA keys offer a middle ground, providing good security with smaller key sizes than RSA, though they've faced scrutiny due to potential implementation vulnerabilities. DSA keys, once common, are now considered deprecated and should be avoided for new implementations due to known security weaknesses.
| Algorithm | Key Size | Security Level | Performance | Compatibility |
|---|---|---|---|---|
| RSA | 2048-4096 bits | High (with 4096 bits) | Moderate | Excellent |
| Ed25519 | 256 bits | Very High | Excellent | Good (modern systems) |
| ECDSA | 256-521 bits | High | Good | Good |
| DSA | 1024 bits | Low (deprecated) | Moderate | Legacy only |
Generating Your First SSH Key Pair
Creating an SSH key pair is straightforward across all major operating systems. On Linux, macOS, and modern Windows systems with OpenSSH installed, the ssh-keygen command provides a unified interface for key generation. This tool guides you through the process, allowing customization of algorithm type, key length, and file location.
The basic command for generating a modern, secure key pair is simple yet powerful. Opening a terminal and executing the key generation command initiates an interactive process that creates both keys and stores them in your user directory. The default location is typically the .ssh folder within your home directory, a hidden folder that maintains appropriate permissions to protect your private key.
Step-by-Step Key Generation Process
🔐 Choose your algorithm: For new keys, Ed25519 provides the best combination of security and performance. The command syntax specifies the algorithm type, allowing you to make an informed choice based on your requirements and the systems you'll be accessing.
🔐 Specify the file location: While defaults work well for single-key scenarios, managing multiple keys for different purposes requires thoughtful naming. Descriptive filenames like "id_ed25519_work" or "id_rsa_personal" help organize keys and prevent confusion when managing access to multiple systems.
🔐 Create a strong passphrase: Adding a passphrase to your private key creates an additional security layer. Even if someone gains access to your private key file, they cannot use it without knowing the passphrase. This defense-in-depth approach significantly enhances security, especially for keys stored on laptops or other portable devices that might be lost or stolen.
🔐 Verify key generation: After generation completes, examining the .ssh directory confirms that both the private key and public key files exist. The public key file has a .pub extension, making it easily identifiable. Checking file permissions ensures the private key remains readable only by your user account.
🔐 Back up your keys securely: Private keys represent your digital identity for the systems they access. Storing encrypted backups in secure locations protects against data loss while maintaining security. Password managers with secure note features or encrypted USB drives stored in physical safes provide appropriate backup solutions.
"A passphrase-protected private key combines something you have—the key file—with something you know—the passphrase—creating two-factor security that dramatically reduces unauthorized access risk."
Understanding Key Fingerprints
Every SSH key has a unique fingerprint—a short, human-readable hash of the key's contents. Fingerprints serve as a way to verify key identity without comparing the entire key content. When you connect to a server for the first time, SSH displays the server's key fingerprint, allowing you to verify you're connecting to the legitimate server rather than an impostor attempting a man-in-the-middle attack.
Modern SSH implementations display fingerprints in multiple formats, including MD5 and SHA256 hashes. The SHA256 format has become standard due to its stronger cryptographic properties. A typical SHA256 fingerprint appears as a string beginning with "SHA256:" followed by base64-encoded characters, providing a compact yet secure representation of the key.
Deploying Public Keys to Remote Systems
After generating your key pair, the next critical step involves copying your public key to the remote systems you need to access. The public key must be added to the authorized_keys file in the .ssh directory of the remote user account. This file acts as a whitelist, containing all public keys permitted to authenticate as that user.
The ssh-copy-id command automates this deployment process on Unix-like systems. This utility connects to the remote server using password authentication one final time, then automatically appends your public key to the authorized_keys file with correct permissions. The command handles the technical details of file creation, permission setting, and key formatting, reducing the chance of configuration errors.
For systems where ssh-copy-id isn't available, manual deployment remains straightforward. Copying the contents of your public key file and appending it to the remote authorized_keys file accomplishes the same goal. Care must be taken to preserve the key's formatting—each public key should occupy exactly one line in the authorized_keys file, with no line breaks within the key itself.
Authorized Keys File Structure and Options
The authorized_keys file supports more than simple key storage. Each line can include options that restrict how that particular key can be used. These options precede the key itself, separated by spaces, and provide granular control over authentication behavior. Understanding these options enables implementing least-privilege access patterns that limit potential damage from compromised keys.
Command restrictions force a specific command to execute whenever someone authenticates with a particular key, regardless of what command they request. This feature proves invaluable for automated systems that need SSH access for specific tasks without granting full shell access. For example, a backup system might use a key restricted to running only backup-related commands.
Source address restrictions limit which IP addresses or networks can use a particular key for authentication. If you know a key will only be used from specific locations—such as your office network or a particular cloud provider—restricting source addresses adds another security layer. Attempts to use the key from unauthorized locations fail automatically, even if an attacker obtains the private key.
Port forwarding controls determine whether a key can be used to create SSH tunnels or forward ports. Disabling these features for keys that don't require them reduces the attack surface. A key used solely for file transfers, for instance, doesn't need port forwarding capabilities.
| Option | Purpose | Example Use Case |
|---|---|---|
| command="..." | Forces specific command execution | Automated backup scripts |
| from="..." | Restricts source IP addresses | Keys used from fixed locations |
| no-port-forwarding | Disables SSH tunneling | File transfer-only access |
| no-agent-forwarding | Prevents SSH agent forwarding | High-security environments |
| no-X11-forwarding | Disables graphical forwarding | Server-only access |
"Properly configured authorized_keys options transform SSH from a simple authentication mechanism into a sophisticated access control system, enabling precise security policies for each key."
Configuring SSH Clients for Key-Based Authentication
While SSH key authentication works with default settings, customizing your SSH client configuration streamlines workflows and enhances security. The SSH client configuration file, typically located at ~/.ssh/config, allows defining connection parameters for different hosts, eliminating the need to specify options with each connection attempt.
Configuration entries specify hostnames, usernames, key files, and various connection options. Creating host-specific configurations means typing a simple alias instead of remembering full connection details. For instance, defining a "webserver" host entry allows connecting with just "ssh webserver" rather than "ssh -i ~/.ssh/specific_key user@webserver.example.com -p 2222".
Essential Configuration Directives
The IdentityFile directive specifies which private key to use for a particular host or group of hosts. This becomes essential when managing multiple keys for different purposes—work servers might use one key while personal projects use another. SSH attempts keys in the order specified, trying each until authentication succeeds or all keys are exhausted.
The User directive sets the default username for connections to specific hosts. Many users maintain different usernames across various systems; defining the correct username in the configuration eliminates a common source of connection errors and streamlines access.
The Port directive specifies non-standard SSH ports. Security-conscious administrators often move SSH services away from the default port 22 to reduce automated attack attempts. Storing port numbers in the configuration file means never needing to remember which servers use which ports.
The ServerAliveInterval and ServerAliveCountMax directives work together to maintain connections through firewalls and NAT devices that might otherwise terminate idle sessions. These keepalive settings prove particularly valuable when working through corporate networks or unreliable internet connections.
Security Advantages Over Password Authentication
SSH key authentication provides numerous security benefits that make it superior to password-based authentication. Understanding these advantages helps justify the initial setup effort and encourages proper key management practices. The security improvements span multiple attack vectors, from brute-force attempts to sophisticated social engineering.
Immunity to brute-force attacks represents perhaps the most significant advantage. Password authentication remains vulnerable to automated systems that try thousands or millions of password combinations. Even complex passwords eventually fall to sufficiently determined attackers with adequate computational resources. SSH keys, by contrast, use cryptographic key lengths that make brute-force attacks computationally infeasible—breaking a 2048-bit RSA key would require more computing power than currently exists on Earth.
The elimination of password transmission across networks prevents interception attacks. Passwords, even when encrypted during transmission, create risk if the encryption is compromised or if users reuse passwords across systems. SSH keys never transmit the private key itself—only cryptographic proofs of possession. An attacker monitoring network traffic gains no useful information for future authentication attempts.
"The computational difficulty of breaking modern SSH keys means that attackers must shift focus from cryptographic attacks to operational security failures—stolen key files, weak passphrases, or social engineering."
Resistance to Common Attack Patterns
Phishing attacks, which trick users into revealing credentials, become ineffective against properly implemented key authentication. An attacker cannot phish something the user doesn't know—the private key file itself. While sophisticated attacks might target the key file directly through malware, this requires significantly more effort and skill than sending fraudulent login pages.
Credential stuffing attacks, where attackers use leaked passwords from one service to access others, fail completely against systems using key authentication. Since each key pair is unique and users don't "remember" keys the way they remember passwords, there's no password to reuse or leak in database breaches.
Man-in-the-middle attacks face additional hurdles with key authentication. While MITM attacks can still occur at the network level, the cryptographic challenge-response mechanism means an intercepting attacker cannot simply replay captured authentication data. Each authentication session uses unique challenge values, preventing replay attacks.
Managing Multiple SSH Keys Effectively
As your infrastructure grows, managing multiple SSH keys becomes inevitable. Different projects, clients, or security contexts often warrant separate keys to maintain proper access boundaries. Effective key management prevents confusion, maintains security, and streamlines workflows across complex environments.
Organizational strategies for multiple keys typically involve descriptive naming conventions and careful configuration file management. Naming keys according to their purpose—such as "id_ed25519_github", "id_rsa_client_projectx", or "id_ed25519_personal_servers"—immediately clarifies each key's role. This clarity becomes invaluable when reviewing keys months or years after creation.
SSH Agent for Convenient Key Management
The SSH agent provides a secure way to manage multiple passphrase-protected keys without repeatedly entering passphrases. This background service holds decrypted private keys in memory, automatically providing them to SSH clients as needed. The agent never writes decrypted keys to disk, maintaining security while dramatically improving usability.
Starting an SSH agent and adding keys to it creates a session where all subsequent SSH connections can access your keys without prompting for passphrases. Modern desktop environments often start SSH agents automatically, integrating them with session management so keys added during login remain available until logout.
Agent forwarding extends the agent's convenience to remote systems. When enabled, SSH connections to remote servers can use keys from your local agent without copying private keys to those servers. This feature proves particularly valuable when jumping through bastion hosts or working with multi-tier infrastructure. However, agent forwarding carries security implications—compromised remote systems could potentially use your forwarded agent to authenticate to other systems during your session.
"SSH agent forwarding should be enabled selectively, only for trusted intermediate systems, as it temporarily grants those systems the ability to authenticate as you."
Key Rotation and Lifecycle Management
Regular key rotation enhances security by limiting the window of vulnerability if a key becomes compromised. Organizations often implement policies requiring key rotation every 6-12 months, though the appropriate interval depends on risk tolerance and operational constraints. Rotating keys involves generating new key pairs, deploying the new public keys to all relevant systems, verifying functionality, and finally removing the old keys.
Maintaining an inventory of where each public key is deployed becomes critical as infrastructure scales. Spreadsheets, configuration management databases, or specialized key management tools help track which keys access which systems. This inventory enables efficient rotation and ensures departing team members' access is completely revoked.
Revoking compromised or obsolete keys requires removing their public keys from all authorized_keys files across your infrastructure. Automation tools like Ansible, Puppet, or Chef can streamline this process, ensuring comprehensive revocation even across hundreds or thousands of systems. Manual revocation on large infrastructures risks missing systems, leaving security gaps.
Enterprise-Scale Key Management
Organizations managing SSH access for dozens or hundreds of users across extensive infrastructure face challenges that personal key management approaches cannot address. Centralized key management, certificate-based authentication, and comprehensive audit capabilities become essential for maintaining security and operational efficiency at scale.
Certificate-based SSH authentication provides a more scalable alternative to managing individual public keys. In this model, a certificate authority (CA) signs short-lived certificates that grant access to systems. Instead of distributing individual public keys to every server, administrators configure servers to trust certificates signed by the CA. Users obtain certificates from the CA, typically with expiration times measured in hours or days, which automatically limits the impact of compromised credentials.
This approach dramatically simplifies access management. When an employee joins, they receive a certificate signed by the CA, granting immediate access to appropriate systems without individually updating hundreds of servers. When they leave, certificate issuance stops, and their existing certificates expire naturally within hours or days. No manual key removal is necessary across the infrastructure.
Audit and Compliance Requirements
Regulatory frameworks increasingly require detailed authentication logging and access reviews. SSH key authentication, while secure, can complicate audit requirements if not properly managed. Implementing comprehensive logging of key usage, including which keys accessed which systems at what times, provides the audit trail regulators demand.
Integration with identity management systems connects SSH key authentication to centralized user directories like Active Directory or LDAP. This integration enables consistent access policies across all authentication methods and simplifies compliance reporting. When auditors ask "who has access to this critical system," the answer comes from a single source of truth rather than examining authorized_keys files across multiple servers.
Privileged access management (PAM) solutions specifically designed for SSH environments provide additional controls. These systems can require approval workflows for certain connections, record full session contents for later review, and enforce time-based access restrictions. While adding complexity, these capabilities prove essential for organizations handling sensitive data or operating in heavily regulated industries.
Troubleshooting Common SSH Key Issues
Despite SSH key authentication's reliability, configuration errors and permission problems occasionally prevent successful connections. Understanding common issues and their solutions enables quick problem resolution, minimizing downtime and frustration.
Permission problems represent the most frequent cause of authentication failures. SSH deliberately refuses to use private keys or authorized_keys files with overly permissive settings, as such permissions could allow other users to read or modify these sensitive files. Private keys must be readable only by their owner (permissions 600 or 400), while the .ssh directory should be 700 and the authorized_keys file should be 600.
Verifying and correcting permissions typically resolves these issues immediately. The chmod command adjusts file permissions to meet SSH's requirements. After permission corrections, testing authentication again usually succeeds. If problems persist, checking parent directory permissions ensures the entire path to the .ssh directory maintains appropriate restrictions.
Debugging Authentication Failures
The verbose mode in SSH clients provides detailed information about the authentication process, revealing exactly where failures occur. Running SSH with the -v flag (or -vv or -vvv for increasing verbosity) displays each step of the connection and authentication process. This output shows which keys are being tried, whether the server accepts the public key, and any error messages from the server.
Server-side logs offer complementary information. The SSH daemon typically logs to /var/log/auth.log or /var/log/secure, depending on the operating system. These logs show authentication attempts from the server's perspective, including reasons for rejection. Common issues revealed in server logs include missing public keys, incorrect authorized_keys file locations, and permission problems the client cannot detect.
"Verbose SSH output combined with server logs provides a complete picture of the authentication process, making even complex configuration issues trackable to their root cause."
Key Format and Compatibility Issues
Different SSH implementations and versions support different key formats. OpenSSH recently changed its default private key format, which can cause compatibility issues with older SSH clients or tools. The newer format provides better security, but legacy systems may require keys in the older PEM format.
Converting between formats using ssh-keygen resolves these compatibility issues. The tool can export keys in various formats, ensuring compatibility across diverse environments. When generating new keys, specifying the desired format from the start prevents later conversion needs.
Some systems have restrictions on which key algorithms they accept. Security-conscious organizations might disable older algorithms like DSA or 1024-bit RSA keys. If authentication fails despite correct key deployment and permissions, verifying that the key algorithm is supported on the target system becomes necessary. Generating a new key with a supported algorithm provides the solution.
Best Practices for Long-Term Key Security
Maintaining SSH key security over time requires ongoing attention and adherence to established best practices. As infrastructure evolves and threats change, security practices must adapt while maintaining operational efficiency.
Always protect private keys with strong passphrases. While the convenience of passphrase-less keys tempts users, the security trade-off rarely justifies the risk. A compromised laptop or stolen backup containing an unprotected private key grants immediate, undetectable access to all systems that trust that key. Passphrases create a crucial second layer of defense, ensuring stolen key files remain useless without additional information.
Store private keys only on trusted, encrypted devices. Copying private keys to multiple locations or storing them in cloud synchronization services increases exposure risk. Each additional copy represents another potential compromise point. Limiting private keys to a single, well-protected location—preferably on encrypted storage—minimizes this risk.
Regular security audits of authorized_keys files across infrastructure identify obsolete or unauthorized keys. As teams change and infrastructure evolves, public keys accumulate in authorized_keys files. Periodically reviewing these files and removing keys that no longer serve a valid purpose reduces the attack surface. Automated tools can scan infrastructure, inventory all deployed public keys, and flag keys not matching known, authorized keys.
Hardware Security Keys for Ultimate Protection
Hardware security tokens like YubiKeys provide the highest level of private key protection by storing keys on tamper-resistant hardware that never allows key extraction. SSH operations requiring the private key occur on the hardware device itself, with only the results returned to the computer. Even if an attacker completely compromises the computer, they cannot extract the private key from the hardware token.
Modern OpenSSH supports FIDO2/U2F hardware tokens, enabling hardware-backed SSH authentication. This approach combines the convenience of key-based authentication with the security of hardware tokens. The main limitation is that the hardware token must be physically present for authentication, which complicates some automation scenarios but provides unparalleled security for interactive access.
Integration with Modern DevOps Workflows
SSH key authentication plays a crucial role in contemporary DevOps practices, enabling automation while maintaining security. Understanding how keys fit into CI/CD pipelines, infrastructure as code, and container orchestration helps implement secure, efficient workflows.
Continuous integration and deployment systems require SSH access to deploy applications and manage infrastructure. These automated systems use dedicated SSH keys, often called deploy keys or machine keys, which should follow even stricter security practices than user keys. Deploy keys typically have restricted permissions, accessing only the specific resources needed for deployment tasks.
Storing deploy keys securely presents unique challenges. Hard-coding keys in scripts or configuration files creates obvious security vulnerabilities. Modern CI/CD platforms provide secure secret storage mechanisms specifically designed for credentials like SSH private keys. These systems encrypt secrets at rest and provide them to build jobs only when needed, logging all access for audit purposes.
Container and Cloud-Native Environments
Container orchestration platforms like Kubernetes use SSH keys for various purposes, from accessing nodes for maintenance to enabling secure communication between components. Managing these keys in dynamic, ephemeral environments requires approaches adapted to cloud-native principles. Secrets management systems like HashiCorp Vault or cloud provider secret managers integrate with orchestration platforms to provide keys on demand, rotating them automatically according to policy.
Infrastructure as code tools like Terraform use SSH keys to configure newly provisioned systems. These tools must access keys securely without embedding them in version-controlled code. Most IaC tools support integration with secret management systems, retrieving keys at runtime rather than storing them in configuration files.
"Modern DevOps practices demand that SSH keys be treated as first-class secrets, managed through dedicated secret management systems rather than stored in code repositories or configuration files."
Future Developments in SSH Authentication
SSH key authentication continues evolving to address emerging security challenges and leverage new technologies. Understanding these developments helps prepare for future infrastructure requirements and security improvements.
Post-quantum cryptography represents the most significant upcoming change to SSH key authentication. Current SSH key algorithms, while secure against classical computers, face theoretical vulnerabilities to quantum computers. As quantum computing advances, the cryptographic community is developing and standardizing post-quantum algorithms resistant to both classical and quantum attacks. Future SSH implementations will incorporate these algorithms, requiring infrastructure updates and key regeneration.
Integration with zero-trust security models is reshaping how organizations approach SSH access. Rather than assuming network location implies trust, zero-trust architectures require continuous verification of identity and authorization. SSH authentication in zero-trust environments increasingly combines key-based authentication with additional context—device health, user behavior analytics, and real-time risk assessment—to make access decisions.
Passwordless authentication movements extend beyond SSH to encompass all system access. While SSH has long supported passwordless access through keys, broader industry adoption of hardware security keys and biometric authentication is influencing SSH implementations. Future versions may more tightly integrate with platform authentication mechanisms, providing seamless security across all access methods.
Frequently Asked Questions
Can I use the same SSH key pair for multiple servers?
Yes, you can use one key pair across multiple servers by copying the public key to each server's authorized_keys file. However, using separate keys for different purposes or security domains is generally recommended. If one key becomes compromised, separate keys limit the breach to only those systems using that specific key. For personal projects with a few servers, one key pair is usually sufficient, while enterprise environments typically implement more granular key distribution.
What should I do if I lose my private key?
If you lose your private key, you cannot recover it—private keys are not stored anywhere except where you created them. You'll need to generate a new key pair and deploy the new public key to all systems that had the old key. This is why backing up private keys securely is important. If you've completely lost access to systems because of a lost key, you'll need to use alternative access methods (password authentication if still enabled, console access for cloud servers, or physical access for local systems) to regain entry and deploy new keys.
Is it safe to commit public keys to version control?
Yes, public keys are designed to be shared openly and can safely be committed to version control systems. The "public" in public key means exactly that—there's no security risk in making them public. Many infrastructure-as-code repositories include public keys that will be deployed to servers. However, never commit private keys to version control, even private repositories, as this creates unnecessary risk and makes key rotation more complex.
How often should I rotate my SSH keys?
Key rotation frequency depends on your security requirements and risk profile. For personal use, rotating keys annually or when changing jobs/projects is typically sufficient. Enterprise environments often mandate rotation every 90-180 days for compliance reasons. Certificate-based SSH authentication enables much shorter lifetimes (hours or days) without operational overhead. More important than any specific timeline is having a documented rotation process and actually following it consistently.
Can SSH keys be hacked or cracked?
Modern SSH keys using appropriate algorithms and key lengths are effectively impossible to crack through brute force with current technology. A 2048-bit RSA key or Ed25519 key would require computational resources far beyond what exists today to break through cryptographic attacks. The real risks come from operational security failures: stolen private key files, weak or absent passphrases, compromised systems where keys are stored, or social engineering attacks. Proper key management and protection practices are far more important than worrying about cryptographic attacks.
Why does SSH refuse my key even though I copied it correctly?
The most common cause is incorrect file permissions. SSH requires private keys to have restrictive permissions (600 or 400) and will refuse to use keys that are readable by other users. The .ssh directory should have 700 permissions, and authorized_keys should have 600 permissions. Other causes include the public key being added incorrectly to authorized_keys (with line breaks or extra characters), the SSH server being configured to not allow key authentication, or the key algorithm being disabled in the server configuration. Using verbose mode (ssh -v) shows exactly where the authentication process fails.