Skip to content

Latest commit

 

History

History
85 lines (56 loc) · 2.48 KB

File metadata and controls

85 lines (56 loc) · 2.48 KB

Create SSH keys for service

Purpose

This script creates a new Ed21559 SSH public and private key-pair for ssh service.

Usage

🚧 Warning

I highly recommend setting passphrases for all keys created, in case the keys are stolen.

In a terminal, run

🚧 Warning

Replace server-hostname with the server's DNS or IP address and replace username with the user name you want to connect to on the server.

create_ssh_key_for_service.sh server-hostname username
  • The script will create the ssh key-pair in the format username@server-hostname in the ~/.ssh folder and add the following to ~/.ssh/config file:

    • Host server-hostname
    • HostName server-hostname
    • User username
    • IdentityFile ~/.ssh/ssh-private-key

Copy the ssh public key .pub to the remote device in ~/.ssh/authorized_keys on the remote.

Enable ssh public key logins on the server

  1. Uncomment lines in /etc/ssh/sshd_config on the server. Lines # PubkeyAuthentication yes and # PasswordAuthentication no.

    sudo nano /etc/ssh/sshd_config

    The file should look like this after editing.

    ...
    # Authentication:
    ...
    PubkeyAuthentication yes
    ...
    PasswordAuthentication no
    ...
    
  2. Copy the public key into ./ssh/authorized_keys file on the server. Without having sshd already setup, it will have to be manually copied by another way.

  3. Enable and start the ssh daemon service on the server.

    sudo systemctl enable sshd.service && sudo systemctl start sshd.service
  4. Unblock port 22 (TCP) ssh in your firewall on the server to be able to now access the device using the public key.

Generate keys for github.

  1. Generate the keys for the github service.

    create_ssh_key_for_service.sh github.com git
  2. Go to https://github.com/settings/keys and click New SSH key.

  3. Give the key a title (Optional), select Key type: Authentication key (Default) and copy the text from git@github.com.pub into the Key textbox.

  4. Click Add SSH key button to complete.

Backup Files

Files are stored in ~/.ssh, these files should be archived and copied to a secure location as a backup.

Permission settings for the .ssh folder should be 700, the *.pub files should be 644 and the private keys and other files should be 600.