Ssh Config Rsa Key



Specifies a file containing a private host key used by SSH. It is possible to have multiple host key files. The default is /etc/ssh/sshhostdsakey, /etc/ssh/sshhostecdsakey, /etc/ssh/sshhosted25519key and /etc/ssh/sshhostrsakey for SSH protocol version 2. Replace ided25519.pub with your filename. For example, use idrsa.pub for RSA.; Sign in to GitLab. In the top right corner, select your avatar. Select Settings.; From the left sidebar, select SSH Keys.; In the Key box, paste the contents of your public key. If you manually copied the key, make sure you copy the entire key, which starts with ssh-ed25519 or ssh-rsa, and may end with a comment. By default ssh looks for the key called idrsa.pub, we have to tell ssh to look for a different public key file depending on the service. This is where the config file comes handy. SSH config file. The config file lives in /.ssh/config, if it’s not there, go ahead and make it: sudo touch /.ssh/config.

How to create ssh keys and manage multiple keys

How to create ssh keys, how to get them safely to your server, and how to manage multiple keys and make ssh-ing into a machine really easy.

For configuring passwordless public key authentication, see ssh-keygen. The ssh program on a host receives its configuration from either the command line or from configuration files /.ssh/config and /etc/ssh/sshconfig. Command-line options take precedence over configuration files. The user-specific configuration file /.ssh/config is used next. Create an SSH key. If you don't have an SSH key pair, open a bash shell or the command line and type in: ssh-keygen -t rsa -b 2048. This will generate the SSH key. Press Enter at the following prompt to save the key in the default location (under your user directory as a folder named.ssh).

Check for existing ssh keys

Ssh Id Rsa

How to ssh with rsa

List files in the default, hidden, ssh directory:

If you don’t have an ~/.ssh directory, go ahead and make it:

Generate the ssh key

Make a key using the ssh-keygen utility, run that command on your local machine:

Ssh Config Key Path

It’ll ask you where to save it, if this is the first key you’re making, then just hit enter and it’ll make it in ~/.ssh/id_rsa. If you already have a key, and want to make new key, then use a different name, like ~/.ssh/id_rsa_foo, it can be anything though.

Next it asks to make a passphrase, it’s a password you have to type when logging in with the key. It can be left blank by hitting enter.

Two files were created:

id_rsa_foo
This is your key file that sits on the local machine.
id_rsa_foo.pub
this is the public file that goes to your remote server.

Now you have the key, go ahead and pop it open to a text editor, or cat it $ cat id_rsa_foo.

Show an example ssh key

And the public file looks approximately like this:

Third step: copy the key to remote server

If you used something like DigitalOcean to create your cloud server, then the key is already there. It’s in /root/.ssh/authorized_keys, to be precise.

But if you don’t have it, there are clever ways to copy it over.

In the remote machine there is a file ~/.ssh/authorized_keys, we need to upload the public key there, there are few way to go about this.

Method 1: ssh-copy-id

Probably the most painless solution, downside being it won't work on OS X (scroll to method #2 if you’re on OS X).

The syntax in whole goes like:

So the custom named pub file would go like this

Method 2: redirecting

This is more verbose but it should work:

Note that a port is specified -p 5555, if you have your ssh listening to a default port, you might not need that.

Method 3: manual copy

Just copy and paste manually the public key, cat it out and just copy it:

Login to the remote server and find the ~/.ssh/authorized_keys and paste it at the end.

Test the ssh connection

Now it should work, test it by exiting your box ($ exit). Then try to ssh back into it by using the new key:

The -i flag stands for identify, and should be a path to the file we just created.

Manage multiple ssh keys

It’s probably good to have many keys, e.g. one for GitHub, one for BitBucket, one for your server. By default ssh looks for the key called id_rsa.pub, we have to tell ssh to look for a different public key file depending on the service. This is where the config file comes handy.

SSH config file

Ssh Config Rsa Key

The config file lives in ~/.ssh/config, if it’s not there, go ahead and make it: sudo touch ~/.ssh/config.

Contents of the file should looks something like:

Host
This can be anything, it’s the shortname.
HostName
IP or host name.
Port
Open port in the server, might not need this.
IdentityFile
Where the key file is.
User
User on the server, this is needed if your user on the server is different than on local machine.

Now, logging in is as easy as: $ ssh myserver.

Add more servers after the first one, if needed:

Conclusions

If you ever have a whiff of doubt that your key is compromised, then make a new one.

How To Ssh With Rsa

Hope this was helpful.