This is a really simple question about SSH. I’m new to this concept and struggling to figure it out.
I get that an SSH key has to be registered on the server and stored on the host computer. But how does the server find the file on the local machine? How does it know the filepath for the .pub file? I could store this key in any local folder, right?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
The server doesn’t find the key on the local machine, the client on your local machine sends it.
On your local machine (not the server). Your user will have (or should have) a .ssh directory. You can find it by typing cd ~/.ssh. In that directory you will have a file called config. This is where you store all of the information about which private (not public) key to use when you try to connect to a remote server. The public key should be added as a single line to a remote server’s authorized_keys file. Just think of it as you keep your private key private and your public key is safe to share. You will want to make sure permissions are set right on the .ssh directory if you have any connection problems. Specifically the IdentityFile line in the config file is what you will need to set if you want to have multiple keys. Example config file:
Host *
# Forward ssh agent to the remote machine.
# This allows you to use services like GitHub on
# all remote servers
ForwardAgent yes
# example.com server
host example 123.123.123.123
hostname example.com
user remoteusername
IdentityFile ~/.ssh/specific_private_key
You can then connect using ssh example instead of ssh remoteusername@example.com or ssh remoteusername@123.123.123.123. You can also add specific ports if necessary. Type man ssh_config for all options.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.