Set up SSH key-based authentication to enable passwordless logins to a remote host. Generate a key pair, install the public key on the server, then validate that the connection succeeds without a password prompt.
You connect to the same remote server frequently and want to remove repeated password entry from your workflow. Your task is to generate an SSH key pair locally, copy the public key to the remote account, and confirm that you can log in using the key. This is a standard operational setup that improves both efficiency and security when combined with strong key protection and server-side policy.
In production environments, key-based access is often paired with disabling password authentication, enforcing modern key types, and constraining access through least-privilege accounts. This lab focuses on the core setup and validation workflow.
ssh-copy-id.
ssh-keygen.
ssh-copy-id.
ssh user@host login.
~/.ssh/*.pub) and private keys
(~/.ssh/id_*).
ssh-keygen -t rsa
This generates a new private/public key pair in
~/.ssh/. The private key stays local and must
be protected. The public key is what you install on the
remote server.
Generating public/private rsa key pair.
Enter file in which to save the key (/home/lab/.ssh/id_rsa):
Created key at /home/lab/.ssh/id_rsa.pub
ssh-copy-id labuser@192.168.1.50
This appends your public key to the remote user's
~/.ssh/authorized_keys file. You typically enter
the remote password once during this step.
/usr/bin/ssh-copy-id: INFO: Source of key: /home/lab/.ssh/id_rsa.pub
Number of key(s) added: 1
Now try logging into the machine, with:
ssh labuser@192.168.1.50
ssh labuser@192.168.1.50
If the key is accepted and permissions are correct, the session should start without prompting for a password.
Welcome to 192.168.1.50. No password required.
exit
This cleanly closes the remote shell and returns you to the local session.
Connection to 192.168.1.50 closed.
ssh-keygen -t rsa
: Generates a new RSA key pair in ~/.ssh/
(private key + public key).
~/.ssh/id_rsa
: Default private key file. Keep this file protected and
never copy it to remote systems.
~/.ssh/id_rsa.pub
: Default public key file. This is the key that gets
installed on the remote server.
ssh-copy-id user@host
: Installs a public key into the remote user's
~/.ssh/authorized_keys.
~/.ssh/authorized_keys
: Remote file containing public keys allowed to authenticate
for the account.
ssh user@host
: Initiates an SSH session. If key-based authentication is
configured correctly, it can succeed without a password
prompt.
exit
: Closes the remote shell session and terminates the SSH
connection.