Security on GitHub: Tokens, SSH and GPG Keys

GitHub is one of the most popular platforms for hosting source code and collaborating on software projects. With millions of users and repositories, security is a primary concern for developers and organizations using the platform. In this context, the use of tokens, SSH keys and GPG keys are essential to guarantee the security and integrity of projects hosted on GitHub.

Personal Access Tokens (PATs)

Personal Access Tokens (PATs) are used on GitHub as a secure alternative to passwords for authenticating to APIs and the command line. They are essential for automating tasks and securely accessing third-party services that interact with your GitHub account.

To create a PAT on GitHub, you must access your account settings, go to the 'Developer settings' section and choose 'Personal access tokens'. When creating a token, you can define the scope of permissions it will have, limiting access to only what is necessary for the task at hand. This is a security practice known as the 'principle of least privilege'.

It is important to never share your PATs and treat them like passwords. Furthermore, it is recommended to rotate them regularly and check the active tokens in your account to remove those that are no longer needed.

SSH Keys

SSH (Secure Shell) is a protocol that provides a secure way to access remote networks or servers. In the context of GitHub, SSH keys are used to establish a secure connection between your local machine and GitHub, allowing operations such as cloning, pushing, and pulling repositories without needing to enter your password for each operation.

To configure an SSH key, you must generate a key pair (public and private) on your local machine. The private key must be kept secret, while the public key is added to your GitHub account. This means that every time you interact with GitHub, the connection will be automatically authenticated using your private key.

The security of SSH keys lies in the fact that the private key is never transmitted during authentication. Additionally, you can add an extra password to your private key for an additional layer of security.

GPG Keys

GPG (GNU Privacy Guard) is a tool for data encryption and signing. On GitHub, you can use GPG keys to sign your commits and tags, ensuring they came from you and haven't been changed.

To start using GPG on GitHub, you must first generate a GPG key pair and add the public key to your GitHub profile. By configuring your development environment to use your GPG key, you can start signing your commits with the private key, which must be kept secure and protected by a password.

Signing your commits with GPG is a recommended practice especially for open source projects, as it increases confidence in the provenance of the code. Additionally, GitHub provides a visual indication on signed commits, making it easier to identify authenticated contributions.

GitHub Security Best Practices

In addition to using PATs, SSH, and GPG keys, there are other security practices you should adopt when using GitHub:

  • Two-factor authentication (2FA): Enable 2FA to add an extra layer of security to your GitHub account.
  • Permissions Review: Periodically review the permissions of contributors and third-party integrations in your repositories.
  • Activity monitoring: Keep an eye on notifications and activity logs on your account to detect any suspicious behavior.
  • Security updates: Keep your software and development tools up to date to protect against known vulnerabilities.
  • Education and training: Invest in security training for yourself and your team to be aware of best practices and emerging threats.

In short, security on GitHub is a shared responsibility between the platform and its users. Using tokens, SSH keys and GPG keys appropriately is essential to protect your account, your repositories and the integrity of your projects. Furthermore, adopting good security practices and remaining vigilant are essential attitudes to maintaining a secure development environment.

Now answer the exercise about the content:

Which of the following statements is true about security practices at GitHub?

You are right! Congratulations, now go to the next page

You missed! Try again.

Article image Privacy and access control on GitHub

Next page of the Free Ebook:

47Privacy and access control on GitHub

5 minutes

Obtenez votre certificat pour ce cours gratuitement ! en téléchargeant lapplication Cursa et en lisant lebook qui sy trouve. Disponible sur Google Play ou App Store !

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text