Skip to content

Generating a Public-Private Key Pair on Your Laptop


Intro

You don't whisper a password through your letter box to get into your house, most people use a key. We will use the same thing for getting access to the student server using SSH protocol.

1. Generate the Key Pair

Open the terminal on your laptop and run the following command:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  • ssh-keygen: Generates a new SSH key.
  • -t rsa: Specifies the type of key to create (RSA).
  • -b 4096: Sets the key length to 4096 bits.
  • -C "your_email@mail.dcu.ie": Adds a label with your email address.

2. Follow the Prompts

You will be prompted for the following:

File location: Press Enter to accept the default location. Passphrase: Optionally enter a passphrase for added security.

Example:

eUser2@student:~# ssh-keygen -t rsa -b 4096 -C "student001@mail.dcu.ie"
Generating public/private rsa key pair.
Enter file in which to save the key (/users/eUser2/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):

3. Copy the Public Key

Once this is complete, you will need to copy your public key to the student.computing.dcu.ie server:

  • Output the contents of the public key just created using the following command "cat ~/.ssh/id_rsa.pub"
cat ~/.ssh/id_rsa.pub

For example, here is the output from my laptop. This Public Key needs to be copied across to termcast.

cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCtK52D770UL4+97wr+AQmmtIbLB74kLlFeQE/OWUIZ6zR0l0QYcR4ulNdYoHrIjmX/92gdayDHvSqjSq1perCN86/nV5b9id9Xh82XlEK5nJvCpdks7KRIYzazYlbdwD35Q4nZ/pI/zIkySrnfyW+aJGxBA6ImZtJAysdcg19J6z38O5Drl0sq9R0jHWUSYEbBaNycd/A+m7zMjmtiODFQoix2oB51L0wjvfHRE8E+MnlmCIAeg5CGeF+tDKemX6ltlK7sqKKQDS6VTwnpKbUUwKuWOqjrHLLRfVmLK1OLYI+0ItNavANpfkOMs4m0PNGkDInMgGT51KK5sFsyYZi1CPJK0uu2EFXKlT22k+O7e+OEt4xKYq5j6WUUzeNcq36WW2OmpTAYf7NSB5cyRMb2FL/vZrPXXfvA0Fwin77IucI9dpckur0pMtHBVwtjFwsTDCa++dNPywR/f1ftKl1oB6UQ== your_email@dcu.ie

4. Log into termcast.computing.dcu.ie and copy YOUR public key to your student.computing.dcu.ie account

  • Copy all the output from ssh-rsa to the email, and add it to the next command.
  • NOTE: Do not delete any existing entries in the ~/.ssh/authorized_keys file
  • Now go to termcast.computing.dcu.ie where you can install the keys with the following command
echo "INSERT YOUR KEY HERE - output from the cat ~/.ssh/id_rsa.pub command" | tee -a ~/.ssh/authorized_keys

For Example[this is my key]:

echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCtK52D770UL4+97wr+AQmmtIbLB74kLlFeQE/OWUIZ6zR0l0QYcR4ulNdYoHrIjmX/92gdayDHvSqjSq1perCN86/nV5b9id9Xh82XlEK5nJvCpdks7KRIYzazYlbdwD35Q4nZ/pI/zIkySrnfyW+aJGxBA6ImZtJAysdcg19J6z38O5Drl0sq9R0jHWUSYEbBaNycd/A+m7zMjmtiODFQoix2oB51L0wjvfHRE8E+MnlmCIAeg5CGeF+tDKemX6ltlK7sqKKQDS6VTwnpKbUUwKuWOqjrHLLRfVmLK1OLYI+0ItNavANpfkOMs4m0PNGkDInMgGT51KK5sFsyYZi1CPJK0uu2EFXKlT22k+O7e+OEt4xKYq5j6WUUzeNcq36WW2OmpTAYf7NSB5cyRMb2FL/vZrPXXfvA0Fwin77IucI9dpckur0pMtHBVwtjFwsTDCa++dNPywR/f1ftKl1oB6UQ== your_email@dcu.ie" | tee -a ~/.ssh/authorized_keys

5. Log in via SSH

Try logging in to the server using SSH:

ssh username@student.computing.dcu.ie

Replace "username" with your actual username.

6. YouTube video example

For a visual guide, you can watch this video tutorial on YouTube.