How to log in to SSH server with GPG key

Prepare GPG key for SSH

The first step when using GPG keys on SSH is to create a new subkey. Doing this will allow SSH authentication details to be shared without affecting your main GPG identity.

Start by opening the GPG prompt for the master key:

gpg --expert --edit-key YOUR-KEY@EMAIL.ADDRESS

Note : You can find the email address for your master key by listing the key's contents: gpg --list-keys .

Type 'addkey' on the GPG prompt, select '8' , then press Enter.

How to log in to SSH server with GPG key Picture 1

Set the subkey capability to '=A' then press Enter.

How to log in to SSH server with GPG key Picture 2

Enter '4096' in the key size prompt, then press Enter .

Set a reasonable time period for subkey validity. In this case, the example would be typing '1y' to make the new subkey only valid for one year.

How to log in to SSH server with GPG key Picture 3

Create a new GPG subkey by typing 'y' , then pressing Enter on the wizard's confirmation prompt.

Type 'quit' , then press Enter to exit the GPG prompt.

Confirm that the new subkey is working properly by getting details about the master key:

gpg --list-keys YOUR-KEY@EMAIL.ADDRESS

How to log in to SSH server with GPG key Picture 4

Enable SSH support in GPG

Once the subkey is up and running, you can now configure your SSH daemon to accept incoming gpg-agent requests. To do that, add 'enable-ssh-support' to the current user's 'gpg-agent.conf' file:

echo "enable-ssh-support" >> ~/.gnupg/gpg-agent.conf

Open the '.bashrc' file with your favorite text editor:

nano ~/.bashrc

Paste the following lines of code at the end of the .bashrc file:

export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
gpgconf --launch gpg-agent

Save the bashrc file, then print the subkey's keygrip:

gpg --list-keys --with-keygrip

How to log in to SSH server with GPG key Picture 5

Copy the subkey's keygrip, then create the file 'sshcontrol' in the .gnupg directory :

nano ~/.gnupg/sshcontrol

Paste your identity keygrip into the new file, then save it.

How to log in to SSH server with GPG key Picture 6

Apply the new SSH and GPG configuration by reloading the bashrc file on the current terminal session:

source ~/.bashrc

Check if the SSH daemon is currently working properly by listing its SSH public key:

ssh-add -l

How to log in to SSH server with GPG key Picture 7

Export and check GPG key

At this point, you should have the SSH daemon correctly linked to your GPG agent. To use it, generate an SSH export key with the following command:

gpg --ssh-export-key YOUR-KEY@EMAIL.ADDRESS > ~/authorized_keys

Set the export key's permission bits to be readable and writable only by the user:

chmod 600 ~/authorized_keys

Send new authorization file to remote server using scp:

scp ~/authorized_keys YOUR-REMOTE.SERVER.DOMAIN:~/.ssh/authorized_keys

Log in to the remote server, then restart the SSH daemon to apply the new key:

sudo systemctl restart ssh.service

Press Ctrl + D , then log back into the remote SSH server. This will bring up a new prompt asking to enter the master GPG key password.

How to log in to SSH server with GPG key Picture 8

Binding a GPG key to the SSH daemon and exporting it to a remote server are just some of the things you can do with SSH. Discover what can be done with this amazing software using SSH with UNIX pipes in Linux.

4 ★ | 1 Vote

May be interested

  • What is the future of server virtualization?What is the future of server virtualization?
    server virtualization can help combat poor server performance, make better use of computing capabilities, limit energy consumption and improve data center flexibility.
  • Learn about the architecture of MS SQL ServerLearn about the architecture of MS SQL Server
    in the previous articles, you already know briefly about sql server, how to install sql server on the computer. in this section we will learn about the architecture of sql server.
  • Instructions for installing MS SQL ServerInstructions for installing MS SQL Server
    this is a step by step guide to installing ms sql server.
  • How to install DNS Server on Windows Server 2019How to install DNS Server on Windows Server 2019
    from microsoft, the domain name system (dns) is one of the industry standard protocol sets that includes tcp / ip, along with dns client and dns server that provide name resolution services that map names to the ip addresses of computers. .
  • Install Windows Server 2003 and create a backup serverInstall Windows Server 2003 and create a backup server
    network management documentation server 2003 as details of how to install, create a companion server in case the main server is malfunctioning, create a domain, join the client to the domain, the conection {remote desktop from the client data to server}, set adsl router parameters to server, turn off 1 working machine immediately.
  • Instructions to change DNS Server on Windows, Mac, iOS and AndroidInstructions to change DNS Server on Windows, Mac, iOS and Android
    by default, your computer will automatically obtain dns information from your isp (isp). sometimes, dns servers are unstable and you are blocked from accessing certain websites. or the default dns server is blocked by some websites for a number of reasons. in this case you should change the dns server with the free public dns server.
  • How to configure DNS Server on Ubuntu Server 11.04How to configure DNS Server on Ubuntu Server 11.04
    dns server is a server with domain name resolution function. in this article, we will detail the steps to install and configure dns server on linux with ubuntu server version 11.04.
  • Instructions for setting up individual FTP Server with FileZillaInstructions for setting up individual FTP Server with FileZilla
    unlike http - designed to forward hyper - text data over tcp connections, standard ftp ensures that the server responds to requests as soon as it receives a signal from the host. not only provides fast and accurate file transfer, but also security, gives users more options in the process of downloading and uploading data ...
  • HAVING clause in SQL ServerHAVING clause in SQL Server
    the having clause is used in conjunction with the group by clause in sql server (transact-sql) to limit the group of returned rows, only when the condition is met is true.
  • What is a RADIUS Server? How does RADIUS Server work?What is a RADIUS Server?  How does RADIUS Server work?
    radius server is a background process that runs on unix or windows servers. it allows you to maintain user profiles in the central database.