Do this once on each computer you work from. The command is the same in the macOS Terminal, a Linux terminal and Windows PowerShell or cmd.
Steps
- Open Terminal (macOS: Applications > Utilities; Linux: your terminal) or PowerShell on Windows (right-click the Start button, choose Terminal or Windows PowerShell).
- Type
ssh-keygen -t ed25519 -C "laptop"and press Enter. The text after-Cis a note for you, such as the computer's name. - Press Enter to keep the suggested file (
.ssh/id_ed25519in your home folder). - Type a passphrase and press Enter, then type it again. It protects the key if your computer is lost.
- Show the public key: on macOS
pbcopy < ~/.ssh/id_ed25519.pubcopies it; on Linuxcat ~/.ssh/id_ed25519.pub; in PowerShellGet-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-Clipboard; in cmdtype %USERPROFILE%\.ssh\id_ed25519.pub | clip.
Result
You have a key pair. The public key, one line starting with ssh-ed25519, is on your clipboard or on the screen.
What to do next
Warning
The file without .pub is your private key. Never send it, paste it into a website or copy it to a server. Only the .pub file is shared.
An older system that does not know Ed25519? Use ssh-keygen -t rsa -b 4096 instead; the file is then id_rsa.pub.
Related articles
- Add or remove an SSH key Put the public key of your computer on your site, limit it to SFTP or to your own addresses, and remove keys you no longer use.
- Create an SSH key with PuTTYgen Make a key with PuTTYgen on Windows, for PuTTY and WinSCP, and copy its public key for your site.
- SSH and SFTP on 7x servers What SSH and SFTP are, why the 7x servers only accept SSH keys, and the details you need to connect.