I suggest restarting from scratch and then, possibly updating the following steps depending on your specific needs.
Configuration, server side:
- Install the SSH client/server:
sudo apt update
sudo apt install openssh-client
- Ensure the SSH server is running:
systemctl status ssh
- Get the IP/hostname of the server that we'll need to configure the client. In the rest of the tutorial, I assume that the IP of the server is
11.22.33.44.
ip addr
- Create the user (if needed) that the client will use:
sudo adduser jdoe
Configuration, client side:
sudo apt update
sudo apt install openssh-client
- Ensure there are no previous ssh profile entries:
mv ~/.ssh ~/.ssh.old
ssh-keygen -t rsa -b 2048
ls ~/.ssh
You should see:
~/.ssh/id_rsa: this is your private key: keep it safe, never put it on an untrusted machine.
~/.ssh/id_rsa.pub: this is your public key: this is what you will install on the SSH server.
Upload your SSH key onto the server:
ssh-copy-id -i ~/.ssh/id_rsa.pub jdoe@11.22.33.44
If successful, server-side, the ~jdoe/.ssh/authorized_keys should now display the client public key (i.e., ~/.ssh/id_rsa.pub). If it fails, see the troubleshooting section at the end of this message.
- Optionally, you could define an alias in
~/.ssh/config. The name of the alias is defined by the Host line:
Host myserver
IdentityFile ~/.ssh/id_rsa
User jdoe
HostName 11.22.33.44
Usage, client side
- When you start your desktop session:
ssh-add # Runs ssh-agent
ssh-add -L # Your identity should be displayed
- To connect to your SSH server, without relying on
~/.ssh/config:
ssh jdoe@11.22.33.44
- To connect to your SSH server, by relying on
~/.ssh/config:
ssh myserver
Troubleshooting
If ssh-copy-id fails, this means that for some reason, the SSH client can't connect to the SSH server.
Server-side:
- Ensure the SSH server is running:
systemctl status ssh
- Check if your SSH username exists (in my example,
jdoe). Note that by default, the SSH server prevents to connect as root.
- Check the password assigned to
jdoe server-side.
Client-side:
- Check your network routing from the client to the SSH server. Assuming no firewall is blocking, the target host should reply to `ping