To close an SSH connection, press the Return key, then type ~.

Using SSH keys

Generate a key:

# On newer systems
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -C ''

# On older systems
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -C ''
The type of key, which defaults to RSA.
The number of bits. This is ignored for the newer Ed25519 scheme.
The filename of the new private key. The public key will have the same filename with .pub appended.
An optional free text comment. On MacOS, it defaults to username@hostname.local.

Add the new key to ssh-agent:

# Start the agent in the background
eval "$(ssh-agent -s)"

# Add the key
ssh-add ~/.ssh/id_ed25519

You can assign keys to specific hosts in ~/.ssh/config:

    User git
    IdentityFile ~/.ssh/codeberg_ed25519

    User git
    IdentityFile ~/.ssh/github_ed25519