<!--
  canonical-url: https://www.avonture.be/blog/linux-ssh-scp
  published:     2025-05-08
  This is a static plain-Markdown mirror generated at build time.
  Visit the canonical URL above for the fully rendered page, with images and interactive components.
-->

# SSH - Launch a terminal on your session without having to authenticate yourself

> Stop typing your SSH password! Learn how to use SSH keys and `ssh-copy-id` to launch a Linux terminal session instantly without having to authenticate yourself every time.

---
![SSH - Launch a terminal on your session without having to authenticate yourself](/img/v2/ssh.webp)

**TL;DR**

This guide explains how to set up passwordless SSH login to your Linux servers. Learn how to generate an SSH key pair, use `ssh-copy-id` to securely transfer your public key to the server, and connect without a password. The tutorial also covers using `scp` for secure file transfers and demonstrates how to create convenient shortcuts for your connections by using a `~/.ssh/config` file, allowing you to connect with a simple alias.

Imagine that you regularly need to connect to your Linux server: you need to launch a tool such as Putty, you need to enter your login, password, etc. and carry out various operations before you can access the terminal.

If your password isn't saved in Putty's configuration, you'll have to launch another tool like a password vault; in short, it's annoying.

In this article, we'll look at how to authenticate once and for all on the server using an SSH key.

*Two articles that build on this one: [How to connect to your hosting server using SSH](/blog/connect-using-ssh-to-your-hosting-server), applied to a real hosting account, and [Master your ssh command and select the host from a list](/blog/ssh-with-fuzzy-finder) once your `~/.ssh/config` holds a dozen aliases.*

> **Information:**
>
> To illustrate this article, let's assume `christophe` is the remote username (this is the username for the server, distinct from your local username) and `my_blog.be` is the remote server address.
>
> Remember to replace these two constants with yours ;-)

## TLDR

Create an SSH key, copy it to the remote server and run an SSH connection. Steps 1 and 2 have to be done just once.

**Steps to fire in your console:**

1. `ssh-keygen -t ed25519 -C "christophe@my_blog.be" -f ~/.ssh/id_ed25519_my_blog`

2. `ssh-copy-id -i ~/.ssh/id_ed25519_my_blog christophe@my_blog.be`

3. `ssh -i ~/.ssh/id_ed25519_my_blog christophe@my_blog.be`

## In-depth

### 1. Creating the SSH key

The first thing to do, only once, is to generate an SSH key on your host for the remote server.

By running `ssh-keygen -t ed25519 -C "christophe@my_blog.be" -f ~/.ssh/id_ed25519_my_blog` (or `ssh-keygen -t rsa -C "christophe@my_blog.be" -b 4096 -f ~/.ssh/id_rsa_my_blog` for the RSA algorithm):

1. You'll create an SSH key for the remote user `christophe` on server `my_blog.be`. You'll get a private key and a public one,
2. The key will be saved on your machine and the filename will be `~/.ssh/id_ed25519_my_blog` for the private key (and will have the `~/.ssh/id_ed25519_my_blog.pub` for the public one),
3. The key will be based on the ed25519 algorithm.

### 2. Copying the key

When this is done, you've to copy the public SSH key to your remote server. To do this, please run `ssh-copy-id -i ~/.ssh/id_ed25519_my_blog christophe@my_blog.be`. This has to be done just once.

1. You'll copy your local SSH public key `id_ed25519_my_blog` on the `my_blog.be` server,
2. The key will be added for the remote user `christophe`,
3. You'll have to provide the password of that user when prompted.

> **Information:**
>
> The `ssh-copy-id` command will append your public key to the `~/.ssh/authorized_keys` file on the server.

### 3. Connect to the server

Now, everything is in place, you can run `ssh -i ~/.ssh/id_ed25519_my_blog christophe@my_blog.be` and it should work because the `id_ed25519_my_blog` public key was already copied on the server `my_blog.be` for the user `christophe`.

> **Information:**
>
> You can display or edit the content of the `~/.ssh/authorized_keys` file by running `cat ~/.ssh/authorized_keys` (or `vi ~/.ssh/authorized_keys`). You can then remove old allowed keys f.i.

## Copying files from your host to the server

Now that we can connect to the server so easily, we can f.i. copy files from our host like this:

```bash
$ scp -i ~/.ssh/id_ed25519_my_blog local_file christophe@my_blog.be:/remote_file
```

First we need to specify our local file (or folder) then where to copy it.

## Copy files from the server to your host

Now, in the other direction, from the server to your host:

```bash
$ scp -i ~/.ssh/id_ed25519_my_blog christophe@my_blog.be:/remote_file local_file
```

## Copying folders

If you need to copy a folder, just add the recursive flag i.e. `-r`.

For instance, `scp -r christophe@my_blog.be:~/backup/ .` will copy the entire `~/backup` folder from the server into my current, local, folder. Really handy.

## Tips

### Running ssh from Microsoft Terminal

The SSH experience is much, much better using Microsoft Terminal than the old Putty application.

With Microsoft Terminal, you can work in a full screen mode, you can have a nice background image, you can work with a much better font (the standard one with Putty is awful), use tabs, ...

If you've already experienced Putty, you know what I mean.

### Using the config file

As we have seen, when using the `ssh` or `scp` command, we need to specify the user name, the name or IP address of the server and the name of the file containing the private key. That's a lot of information to provide, isn't it?

What's more, like me, I can't remember all this information. I just want to connect to my application server and that's it!

It would be nice to be able to ssh my\_application and that's it. No? This is the purpose of the `~/.ssh/config` file!

To connect on that server, my ssh command looks like this: `ssh christophe@my_blog.be -i ~/.ssh/id_ed25519_my_blog`. Not easy to remember!

Let's create a `~/.ssh/config` file. If the file already exists, just edit it: `code ~/.ssh/config`.

Add these lines in the file:

**\~/.ssh/config**

```
Host my_app
    Hostname my_blog.be
    User christophe
    IdentityFile ~/.ssh/id_ed25519_my_blog
```

Save the file and go back to the console.

Now, you can just run `ssh my_app` to make the connection. Pretty easy no?

Want more info? Continue your reading <https://linuxize.com/post/using-the-ssh-config-file/>

## Going further

Once your `~/.ssh/config` file starts to grow with aliases, two companion articles are worth a look: [SSH - Autosuggestions with ZSH](/blog/zsh-plugin-ssh-config-suggestions), so you never have to remember an alias again, and [Using sftp on the command line](/blog/linux-sftp-cli) if you need the sftp counterpart of `scp`.
