Creating a Cloud Server and Acessing with SSH Keys Using Windows Powershell on Hetzner


 

  1. Make sure you have Powershell version 5.1 or better 
    1. Open Powershell, type: $PSVersionTable.PSVersion
    2. Install update if you don't have it: https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows
  2.  Make sure you have the SSH service installed
    1. Type: ssh
    2. If you get an error, install ssh: https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse?tabs=powershell
  3. Create an SSH key (from: https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement)
    1. Type: ssh-keygen -t ed25519 ('ed25519 is the type of key you're generating)
    2. This will produce output:
      1. Generating public/private ed25519 key pair.
        Enter file in which to save the key (C:\Users\username/.ssh/id_ed25519):
    3. Type enter to accept the default name or type a different filename and type enter
    4. You will be asked to type a passphrase. Enter a passphrase if you wish, or just type Enter for no passphrase
    5. This will generate a private key and a public (.pub) key as follows:
      1. Mode                LastWriteTime         Length Name
        ----                -------------         ------ ----
        -a----         6/3/2021   2:55 PM            464 ed25519
        -a----         6/3/2021   2:55 PM            103 ed25519.pub
  4. Make your Powershell SSH agent start automatically (from: https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement) (you probably only have to do this once, and it might not work)
    1. Make sure you're running PowerShell as an administrator
    2. Set the startup type. Type: Get-Service ssh-agent | Set-Service -StartupType Automatic
    3. Start the service. Type: Start-Service ssh-agent
    4. Load your key: ssh-add $env:USERPROFILE\.ssh\id_ed25519
      1. Note: $env:USERPROFILE is just your home directory (eg., for me, C:\user\steph)
      2. So I just CD right into the .ssh directory: cd C:\user\steph\.ssh
      3. Then I just just type this: ssh-add id_ed25519
  5. Create a new server on Hetzner
    1. Create an account on Hetzner
    2. Open the Clod console: https://console.hetzner.cloud/projects
    3. Create a new Project and give it a name
    4. Click on the 'Add Server' button
    5. Select your configuration from the options provided. I used:
      1. Location: Nuremberg
      2. Image: Ubuntu 22.04
      3. Type: Shared vCPU
      4. Configuration: CX31 (  2 CPUs, 8 GB RAM, 80 GB Disc, etc)
      5. Networking: both IPv4 and IPv6
      6. SSH Keys:
        1. Click 'Add SSH Key'
        2. Open your SSH public key in a text editor (in this case, C:\user\steph\.ssh\id_ed25519.pub)
        3. Copy all the text
        4. Paste the text into the form where it says: SSH key
        5. It should automatically assign a name from the public key (it's aty the very end of the text you copied)
        6. Click 'Add SSH Key'
      7. Create Volume: 40 gigabites
      8. Don't select Firewall (do that manually later)
      9. Select Backup
      10. Don't select placement groups, label or cloud config
      11. Enter an easy-to remember name
      12. Click 'Create and Buy Now' (lower Right)
  6. Associate the key with the server
    1. Get the IP address for the server (It's at the top of the page) eg. 195.201.216.204
    2. Log in to your server ssh -i id_ed25519 root@195.201.216.204
      1. Note: -i specifies the name of your key you're using.
      2. (If this doesn't work, try typing: Start-Service ssh-agent )
  7. Enjoy! 


Comments

Popular Posts