Technical Anshu
Tutorials Blog
Login Security

SFTP Key Login Setup and Turning Off Password Login

Password guessing is automated, patient and free for the attacker. Key login replaces the guessable secret with a file that never travels the network. This guide sets it up and closes the password door behind you - without locking yourself out.

By Technical AnshuUbuntu Server8 minute read
Watch the complete Ubuntu SFTP server setup step by step in the video

Your server proves who it is with a host key; keys let it demand the same proof from you. The client keeps a private key that never leaves its machine, the server keeps the matching public key, and login becomes a mathematical handshake instead of a typed secret. The delicate part is the order of operations: keys first, tested second, password door closed last.

Client side - creating and installing your key
$ ssh-keygen -t ed25519
$ ssh-copy-id [email protected]
...and you are in, with no password typed at all.
Three commands: make the key, place the public half on the server, prove it works. Server address shown is an example.
1

Create the Key Pair on the Client

On the computer you will connect from, run ssh-keygen -t ed25519 and accept the default location. Set a passphrase on the private key when asked - it is the lock on the key itself.

Two files appear: id_ed25519 is the private key and stays secret on this machine forever. id_ed25519.pub is the public half and is the only part that ever travels.

Windows users can run the same command in PowerShell, since modern Windows ships an OpenSSH client, or generate the key inside PuTTYgen if they live in WinSCP - the Windows connection guide in this series covers that side.

2

Install the Public Key on the Server

ssh-copy-id [email protected] appends your public key to the server account's ~/.ssh/authorized_keys file, with the right permissions set for you. Type the account password one last time to authorise it.

If you must do it by hand, the permissions are the step everyone gets wrong: the .ssh folder must be chmod 700 and authorized_keys must be chmod 600, both owned by the user. SSH silently ignores a key file that other users can read or write - silent, with no error message, which is why this deserves its own paragraph.

3

Test in a New Window Before Changing Anything

Open a second terminal or client window and log in. You should land inside without a password prompt for the account (your key passphrase is a different, local prompt - that one is fine).

Keep the first session open the whole time. It is your ladder back in if anything in the next step disagrees with your server. Every lockout story in IT begins with someone closing the working session too early.

4

Turn Off Password Login

Now edit /etc/ssh/sshd_config on the server and set:

  1. PasswordAuthentication no
  2. PubkeyAuthentication yes (it is on by default, but confirm it)
  3. Check the drop-in folder too: a file inside /etc/ssh/sshd_config.d/ can override the main file, which is a common reason the change seems ignored on cloud images
  4. Apply with sudo systemctl restart ssh from your still-open session
  5. Test one more fresh login, then try a login from a machine without the key - it must now be refused

The honest trade-off, stated plainly: whoever loses the only private key loses access. There is no password fallback to rescue you by design. Keep a backup of the key in a safe place, and give a second admin their own key rather than sharing yours - two keys, two names in the log.

🔴 The one rule of this guide: never restart SSH with password login disabled until a key login has succeeded in a separate window. The two-window test takes one minute and prevents the classic self-lockout.

Watch the Full Video

See the whole Ubuntu SFTP setup done live, with the exact clicks and commands, in the Technical Anshu video.

Watch Full Video
Frequently Asked Questions

Can a key be brute forced like a password?

Realistically, no. A password has a human-sized number of possibilities and machines try millions. A modern key's possibilities are astronomically larger, and the private half is never sent over the network to be captured.

I lost my private key. Am I locked out forever?

From the network, yes - that is the point of the setting. Recovery means physical or console access to the server, or another admin account whose key still works. This is why a backup key copy and a second admin key are part of the setup, not extras.

Should every user have their own key?

Yes. One key per person means the logs name a person, and removing one person's access is deleting one line from authorized_keys instead of changing a shared password everywhere.

This guide is based on the Technical Anshu Ubuntu SFTP server video - Stuck on a step? Ask in the video comments and you will get a reply.