Ke's Notes and Blogs logo
  • Blogs 
  • Notes 
  1. Home
  2. Notes
  3. SSH Client and Server

SSH Client and Server

Posted on November 5, 2024 • 2 min read • 305 words
Linux   SSH  
Linux   SSH  
Share via
Ke's Notes and Blogs
Link copied to clipboard

Set up SSH client and server.

On this page
  • SSH Server
  • SSH Client
  • Optionally Disable SSH Password Authentication
  • Use SSH Agent Forwarding to Allow git clone on Server
  • References

This page describes how to set up a Ubuntu machine as SSH server to allow clients to remote in.

SSH Server  

First install openssh-server.

sudo apt-get install openssh-server

Afterwards check if the sshd service is active.

sudo systemctl status sshd

SSH Client  

First generate an SSH key pair.

ssh-keygen -t ed25519 -C <label>

Add the public key to the SSH server, this time using password authentication of the user.

ssh-copy-id -i $PUBLIC_KEY_PATH ${USER}@${HOST}

Put the following section in ~/.ssh/config. Replace <***> with the values of the same-named environment variables above:

Host <HOST>
    User <USER>
    IdentityFile <PUBLIC_KEY_PATH>

Remote into the SSH server with the following command.

ssh ${USER}@${HOST}

Optionally Disable SSH Password Authentication  

After setting up SSH Key authentication for one user, we can optionally disable SSH password authentication on the server altogether.

Open the file /etc/ssh/sshd_config. Find the line with:

#PasswordAuthentication yes

Change it to:

PasswordAuthentication no

Then restart the sshd service.

sudo systemctl restart sshd

Use SSH Agent Forwarding to Allow git clone on Server  

When cloning a private GitHub repository over SSH on the server, the server needs access to the SSH private key. It is not secure to place the SSH private key file directly on the server. The better option is to enable SSH agent forwarding on the client and forward the private key from client to server when they are connected.

For example, to set up agent forwarding for github.com put the following contents in ~/.ssh/config:

Host <server_ip_v4>
    ForwardAgent yes
Host github.com
    User git
    AddKeysToAgent yes
    IdentityFile <path_to_private_key_file>

The ForwardAgent yes option shares the client’s private keys with the server whenever there is a connection, so should be used with caution. In particular, it is best to use specific IP addresses or host names in the first rule, instead of using wildcard.

References  

  • OpenSSH configuration
  • SSH Key authentication
  • Troubleshooting SSH agent forwarding
 GPG for GitHub
Debian 12 Post Installation Steps 
On this page:
  • SSH Server
  • SSH Client
  • Optionally Disable SSH Password Authentication
  • Use SSH Agent Forwarding to Allow git clone on Server
  • References
Copyright © 2025 Ke's Notes and Blogs All rights reserved. | Powered by Hinode.
Ke's Notes and Blogs
Code copied to clipboard