Install an SSH Public Key on a Server from Linux, macOS, or Windows
Password prompts on every SSH connection get old quickly. Public-key authentication fixes that, but first the server needs your public key in the right place. On Linux, ssh-copy-id handles the common case. On macOS and Windows, you may need to install or use an alternative. Before copying a key You need a key pair and a way to log in to the server already, such as a password or another working…
Adding an SSH public key to a server streamlines future logins. Public-key authentication means no more typing passwords, but it requires installing the key first. Linux users can rely on ssh-copy-id for the usual case. On macOS and Windows, alternative methods are needed. Before copying a key, you must have a key pair and an existing way to log in, like a password or another key.
Generating an Ed25519 key pair with ssh-keygen is how you start. The public key ends in .pub, while the private key doesn't. Only the public key should be copied, not the private key contents. On Linux, ssh-copy-id is used to append the public key to the authorized_keys file on a remote account. Specifying the public key explicitly avoids installing the wrong identity.
On macOS, ssh-copy-id isn't built-in, but it can be installed via Homebrew. Alternatively, the public key can be copied to the clipboard using pbcopy. On Windows, PowerShell commands can pipe the public key to the remote server. After copying the key, testing the new connection is crucial. A second terminal session with ssh user@host confirms the installation worked.
If password login is disabled, alternative methods must be used to install the key, such as accessing the server's console or adding the key through the provider's interface when initially creating the instance.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.