gh ssh-key: Manage GitHub SSH keys from the command-line

The “gh ssh-key” command is a feature of GitHub CLI (Command-Line Interface) that allows users to manage their SSH keys for GitHub directly from the command line. SSH keys are a secure way to authenticate and establish encrypted connections between a local machine and a remote server, such as GitHub.

With the “gh ssh-key” command, users can conveniently create, view, list, and delete SSH keys associated with their GitHub account or repositories without needing to access the GitHub web interface.

Here are some commonly used subcommands with “gh ssh-key”:

  • gh ssh-key add: This subcommand enables users to add a new SSH key to their GitHub account. Users can specify the key’s title and provide the key material either by entering it manually or by specifying a file containing the key.
  • gh ssh-key list: This subcommand lists all the SSH keys associated with the authenticated GitHub account. It displays information such as the key ID, title, and fingerprint.
  • gh ssh-key view: This subcommand allows users to view the details of a specific SSH key, including the key material and associated metadata.
  • gh ssh-key remove: This subcommand enables users to delete a specific SSH key from their GitHub account.

Managing SSH keys through the “gh ssh-key” command provides a streamlined workflow, allowing users to perform key-related operations directly from their command-line environment. This is particularly useful for developers and system administrators who work extensively with SSH-based authentication.

It’s important to note that the “gh ssh-key” command requires appropriate permissions and authentication to access and modify SSH keys. Users should ensure they have the necessary privileges and proper authentication set up before using this command.

By providing a command-line interface for SSH key management, the “gh ssh-key” command enhances the efficiency and accessibility of managing SSH keys for GitHub. It simplifies the process of adding, viewing, and removing SSH keys, enabling users to securely authenticate and interact with GitHub repositories and services.

gh ssh-key Command Examples

1. Display help:

# gh ssh-key

2. List SSH keys for the currently authenticated user:

# gh ssh-key list

3. Add an SSH key to the currently authenticated user’s account:

# gh ssh-key add /path/to/key.pub

4. Add an SSH key to the currently authenticated user’s account with a specific title:

# gh ssh-key add --title title /path/to/key.pub
Related Post