How to Generate SSH Key

By September 1, 2017June 15th, 2026Emerging Tech
sshkey bg
  • SSH keys use public-key cryptography to authenticate server access without relying on passwords.
  • Checking for an existing key before generating a new one prevents duplicate or conflicting credentials on your system.
  • Storing your private key with a passphrase adds a second layer of protection that a brute-force attack cannot bypass.

Password-based server logins are a weak link in any deployment pipeline. SSH keys remove that risk by replacing credentials with a cryptographic key pair that authenticates through a challenge-response mechanism rather than a string a script can guess. This guide covers how to generate SSH keys correctly, a step our San Diego engineering team includes in every new environment setup.

Credential Vulnerability: How SSH Key Authentication Solves It

SSH keys identify you to a server using public-key cryptography. You generate a matched pair: a public key that lives on the server and a private key that stays on your machine. When you connect, the server issues a challenge encrypted with your public key. Only your private key can decrypt it. No password is transmitted, and no amount of brute-force guessing against the server can reconstruct the private key.

Before generating a new pair, check whether keys already exist on your machine. Open Terminal and run:

ls -al ~/.ssh

Review the directory listing to see if a public key file is already present.

ssh key

 

 

 

If no keys exist, or if you need a fresh pair for a new project or server, proceed to generation. Skipping this check and generating blindly can leave orphaned keys that clutter your ~/.ssh directory and cause authentication confusion later, a pattern our team sees often on inherited codebases.

Weak Key Configuration: The Engineering Decision That Fixes It

Key type and storage decisions at generation time determine how secure and maintainable your authentication setup will be. RSA remains a widely supported standard across server environments. To generate a new RSA key pair, run:

ssh-keygen -t rsa

SSH-Key

 

 

 

The keygen process will prompt you for two decisions. First, it asks where to save the key. Pressing Enter accepts the default path (~/.ssh/id_rsa), which is the right choice for most setups. Second, it asks for an optional passphrase. Adding one means anyone who obtains your private key file still cannot use it without the passphrase, which is a meaningful security layer worth enabling on any production environment. You can learn more about secure infrastructure practices in our cloud security best practices guide.

Generate-SSH-Key

Once the process completes, your public key is stored at ~/.ssh/id_rsa.pub and your private key at ~/.ssh/id_rsa. The public key is what you place on any server you want to access. The private key never leaves your machine. Keep it out of version control and never share it.

What Our San Diego Team Flags in Projects That Skip Key Hygiene

Development teams in San Diego working across cloud deployments and CI/CD pipelines often treat SSH key setup as a one-time task that gets done once and forgotten. The real gap we see is not in generating the key but in managing it: no passphrase, keys shared across team members, and public keys that stay on a server long after a developer leaves a project.

The fix is treating key management the same way you treat dependency management. Each developer holds their own key pair. Access is granted and revoked at the public key level on the server. Projects that adopt this discipline from day one spend significantly less time debugging authentication issues during deployments.

Conclusion

SSH key authentication is more secure than passwords and straightforward to set up when you follow the right sequence: check first, generate with a passphrase, and separate your public and private key responsibilities. Start by auditing your existing ~/.ssh directory before adding new keys. For teams building on shared infrastructure, establish a key rotation policy early rather than retrofitting it later when access management becomes a problem.

Frequently Asked Questions

What is an SSH key? +

An SSH key is a cryptographic credential pair used to authenticate a user to a remote server. The public key is placed on the server, and the private key stays on the user’s machine. When the two match during a connection attempt, access is granted without transmitting a password.

SSH key vs. password: which is more secure? +

SSH keys are significantly more secure than passwords. A brute-force attack can eventually crack a password given enough attempts, but a properly generated SSH key pair is computationally infeasible to guess. Adding a passphrase to the private key makes the setup even more resistant to compromise.

How do I generate an SSH key on Mac or Linux? +

Open Terminal and run ssh-keygen -t rsa. The tool will prompt you to choose a save location (press Enter for the default) and to set an optional passphrase. Your public key will be saved at, ~/.ssh/id_rsa.pub and your private key at ~/.ssh/id_rsa.

Should I add a passphrase to my SSH key in San Diego development environments ? +

Yes, especially on machines used for production server access. A passphrase protects the private key file if your local machine is ever compromised. Development teams in San Diego working across multiple cloud environments should treat passphrase-protected keys as a baseline practice, not an optional step.

What is the difference between a public key and a private key? +

The public key is designed to be shared. It gets placed on any server you want to connect to. The private key is kept only on your local machine and must never be shared or committed to a repository. Authentication works because only the private key can complete the challenge issued by the server using the public key.

Is it worth generating a new SSH key for every project? +

Generating project-specific keys is worth doing for production systems and client environments. It limits the blast radius if a key is compromised and makes access revocation cleaner. For personal development environments, a single well-protected key pair is generally sufficient.

Raj Sanghvi

Raj Sanghvi is a technologist and founder of Bitcot, a full-service award-winning software development company. With over 15 years of innovative coding experience creating complex technology solutions for businesses like IBM, Sony, Nissan, Micron, Dicks Sporting Goods, HDSupply, Bombardier and more, Sanghvi helps build for both major brands and entrepreneurs to launch their own technologies platforms. Visit Raj Sanghvi on LinkedIn and follow him on Twitter. View Full Bio

Leave a Reply