# Linux: Manually Installing SSH Keys

Here's some steps on how to manually install SSH public keys in a host.

#### 1. SSH Key Folder<button aria-hidden="true" class="cc-vhh4ux" data-testid="anchor-button" type="button"><svg class="_1reo15vq _18m915vq _syaz1r31 _lcxvglyw _s7n4yfq0 _vc881r31 _1bsbpxbi _4t3ipxbi" fill="none" role="presentation" viewbox="0 0 16 16"></svg></button>

Navigate to the home folder for the user, with the following command:

```bash
cd /home/username
```

Check if the .ssh folder exists (it is hidden, requiring the -a switch):

```bash
ls -al
```

If the .ssh folder does not exist, create it with the following commands (from the user folder):

```bash
sudo mkdir ~/.ssh
```

```bash
sudo chmod 0700  ./.ssh
```

#### 2. SSH Key File

Enter the ssh key folder with:

```bash
cd ./.ssh
```

And, check if any key files are there, with:

```bash
ls -l
```

[![image.png](https://wiki.galaxydump.com/uploads/images/gallery/2025-09/scaled-1680-/3Mcn7KKxyMbGIyTR-image.png)](https://wiki.galaxydump.com/uploads/images/gallery/2025-09/3Mcn7KKxyMbGIyTR-image.png)

Make sure the key file has the same name that was defined in the ssh config file, in previous steps.

If no key file, create one with (making sure to use the correct key file name):

```bash
sudo touch ./authorized_keys
```

Set permissions on the key file:

```bash
sudo chmod 600 ./authorized_keys
```

#### From Windows

This section is for copying the public key string from a Windows, host.

The tricks to successfully pasting in an SSH key to the ssh key file are:

- Always paste the key string as a single line
- The key string must being with, “ssh-rsa“
- Strip out any “Begin SSH2 PUBLIC KEY” and ending
- The key line should contain the key comment at the end of the line, for easy identification
- A key string should be of the form: ssh-rsa \[really long base64 key string here\] \[key comment\]
- Single whitespace is needed between each component of the key line
- The key comment must have no whitespace in it

The easiest way to get this string is to load a key in PuttyGen.  
Then, paste the entire key string directly from the text window of the form, like this:

[![image.png](https://wiki.galaxydump.com/uploads/images/gallery/2025-09/scaled-1680-/QzY2Ss7qNnaMRONl-image.png)](https://wiki.galaxydump.com/uploads/images/gallery/2025-09/QzY2Ss7qNnaMRONl-image.png)

#### From Linux

If you do not have password-based SSH access to your server available, you will have to complete the above process manually.

We will manually append the content of your <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">id\_rsa.pub</span> file to the <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">~/.ssh/authorized\_keys</span> file on your remote machine.

To display the content of your <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">id\_rsa.pub</span> key, type this into your local computer:

```bash
cat ~/.ssh/id_rsa.pub
```

You will see the key’s content, which should look something like this:

```
Outputssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCqql6MzstZYh1TmWWv11q5O3pISj2ZFl9HgH1JLknLLx44+tXfJ7mIrKNxOOwxIxvcBF8PXSYvobFYEZjGIVCEAjrUzLiIxbyCoxVyle7Q+bqgZ8SeeM8wzytsY+dVGcBxF6N4JS+zVk5eMcV385gG3Y6ON3EG112n6d+SMXY0OEBIcO6x+PnUSGHrSgpBgX7Ks1r7xqFa7heJLLt2wWwkARptX7udSq05paBhcpB0pHtA1Rfz3K2B+ZVIpSDfki9UVKzT8JUmwW6NNzSgxUfQHGwnW7kj4jp4AT0VZk3ADw497M2G/12N0PPB5CnhHf7ovgy6nL1ikrygTKRFmNZISvAcywB9GVqNAVE+ZHDSCuURNsAInVzgYo9xgJDW8wUw2o8U77+xiFxgI5QSZX3Iq7YLMgeksaO4rBJEa54k8m5wEiEE1nUhLuJ0X/vh2xPff6SQ1BL/zkOhvJCACK6Vb15mDOeCSq54Cr7kvS46itMosi/uS66+PujOO+xt/2FWYepz6ZlN70bRly57Q06J+ZJoc9FfBCbCyYH7U/ASsmY095ywPsBo1XQ9PqhnN1/YOorJ068foQDNVpm146mUpILVxmq41Cj55YKHEazXGsdBIbXWhcrRf4G2fJLRcGUr9q8/lERo9oxRm5JFX6TCmj6kmiFqv+Ow9gI0x8GvaQ== demo@test

```

Access your remote host using whichever method you have available.

Once you have access to your account on the remote server, you should make sure the <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">~/.ssh</span> directory exists. This command will create the directory if necessary, or do nothing if it already exists:

```bash
mkdir -p ~/.ssh
```

Now, you can create or modify the <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">authorized\_keys</span> file within this directory. You can add the contents of your <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">id\_rsa.pub</span> file to the end of the <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">authorized\_keys</span> file, creating it if necessary, using this command:

```bash
echo public_key_string >> ~/.ssh/authorized_keys
```

In the above command, substitute the <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">public\_key\_string</span> with the output from the <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">cat ~/.ssh/id\_rsa.pub</span> command that you executed on your local system. It should start with <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">ssh-rsa AAAA...</span>.

Finally, we’ll ensure that the <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">~/.ssh</span> directory and <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">authorized\_keys</span> file have the appropriate permissions set:

```
chmod -R go= ~/.ssh
```

This recursively removes all “group” and “other” permissions for the <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">~/.ssh/</span> directory.

If you’re using the **root** account to set up keys for a user account, it’s also important that the <span class="code" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code" spellcheck="false">~/.ssh</span> directory belongs to the user and not to **root**:

```bash
chown -R sammy:sammy ~/.ssh
```

<p class="callout info">NOTE: The above example uses sammy as the username. Change this to the appropriate username for the target account.</p>

### Connecting to SSH Server from Windows

See this page for steps on how to connect to a Linux host from Windows: [Connecting to SSH Server from Windows](https://wiki.galaxydump.com/link/441)