Generate SSH Key Pair

From AquaWiki
Jump to navigation Jump to search

For Linux[edit]

Run the following. ed25519 is shorter than RSA but offers at least the same security.

   $ ssh-keygen -t ed25519 -C "your_email@example.com"

If for whatever reason, you are unable to produce the above key use the following

   $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com" 

ssh-keygen will generate a key pair using your email as a label, it will then prompt for a path to save, just hit enter for the default location. You'll then be prompted to provide a password, which is good practice but generally I do not, out of convenience 🙃.

For convenience create the following file in ~/.ssh/config

   # Aquarian GitLab instance
   Host gitlab.aquarian.biz
     PreferredAuthentications publickey
     IdentityFile ~/.ssh/example_com_rsa_or_ed

For Windows[edit]

https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse?tabs=powershell This should work for Windows Server 2022, Windows Server 2019, Windows 10 (build 1809 and later). I don't have a windows computer with me so please update as needed. Open power shell as admin and run the following to see if openssh is already installed

   Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'

This should return not present, now run the following to install OpenSSH

   AAdd-WindowsCapability -Online -Name OpenSSH.Client

I would close the PowerShell window, and open it again as admin so the new terminal has the path for what was installed (idk if this is needed but it sounds good). ssh-keygen should have been installed, so the above linux steps should be used to generate the key pair.