dsa Command in Linux



The Linux dsa command processes the Digital Signature Algorithm (DSA) keys. It is a part of OpenSSL; an open-source toolkit for TLS and SSL protocols. The openssl dsa command essentially creates, displays, and converts dsa keys.

The DSA keys are used for digital signatures, which ensure data authentication and integrity. It plays a crucial role in securing data communication.

Table of Contents

Here is a comprehensive guide to the options available with the dsa command −

Prerequisites to Use the dsa Command

The dsa command is a part of OpenSSL, therefore, OpenSSL must be installed in Linux. To check whether it is installed or not, use the following command −

openssl version -a
Prerequisites to Use the dsa Command

If the output does not show any version, follow the instructions below to install it.

To install OpenSSL on Ubuntu, its variants, Debian, and Debian-based distributions −

sudo apt install openssl

To install it on RHEL, and CentOS, use the following command −

sudo yum install openssl

Syntax of dsa Command

The syntax of the openssl dsa command is as follows −

openssl dsa [options]

The [options] field is used to specify the various options to process the dsa keys.

dsa Command Options

The options used with the openssl dsa command are listed below −

Options Description
-inform It is used to specify input format DER (Distinguished Encoding Rules) or PEM (Privacy Enhanced Mail); the default is PEM
-outform It is used to specify the output format DER or PEM
-in filename It is used to specify the filename to read a key from
-passin arg It is used to specify the source of the password input file
-out filename It is used to specify the output file name to write the output (output filename should be different from input filename)
-passout arg It is used to specify the source of the password output file
-des | -des3 | -idea These options (ciphers) are used to specify the encryption of private key
-text It displays the public and private key components and parameters in human-readable form
-noout It suppresses the output of an encoded key
-modulus It displays the public key modulus
-pubin It treats an input file as a public key
-pubout It outputs a public key
-engine id It is used to specify the engine through a string of id

Examples of dsa Command in Linux

This section elaborates on the usage of the openssl dsa command with examples −

Generating a DSA Key Pair

To generate a DSA key without encryption, first get the parameter file. To create a parameter file of 2048 key length, use.

openssl dsaparam -out dsaparam.pem 2048

Next, generate a private key using the parameter file −

openssl gendsa -out private.pem dsaparam.pem

Finally, generate a public key, using the private key using the openssl dsa command −

openssl dsa -in private.pem -pubout -out public.pem
Generating DSA Key Pair

Encrypting a Key

To encrypt a private key with a triple DES or DES, use the following command −

openssl dsa -in private.pem -des3 -out encryptedkey.pem
Encrypting a Key dsa Command

The command will prompt for the passphrase, type it to complete the encryption.

Now whenever someone accesses the key, a passphrase prompt will appear.

Removing the Passphrase of a Key

A passphrase is a sequence of words, or characters used to access a device or file. It is similar to a password, but much more complex and longer than a password.

To remove the passphrase of a DSA key, use the following command −

openssl dsa -in encryptedkey.pem -out keyout.pem
Removing Passphrase of a Key

If the key is already encrypted a passphrase prompt will appear. It removes the passphrase protection and writes it to the keyout.pem file.

Converting Key Format

If the private key is in PEM format, then it can be converted to DER by using the openssl dsa command −

openssl dsa -in private.pem -outform DER -out keyout.der
Converting Key Format

Similarly, the public key can also be converted to DER format.

Displaying Components of a Key

To display the components of the key, the -text option is used −

openssl dsa -in private.pem -text
Displaying Components of a Key 1

The above command also prints the base64 encoded key. To prevent it from displaying to standard output, use the -noout option −

openssl dsa -in private.pem -text -noout

The encoded key appears at the end of the above command output and looks like as −

Displaying Components of a Key 2

Removing the encoded key makes it easy to parse data.

Displaying the Public Key Component of a Private Key

To display the public part of a private key, use -modulus option −

openssl dsa -in private.pem -modulus -noout
Displaying Public Key Component of Private Key

Conclusion

The dsa command in Linux is a part of OpenSSL, which is used to process DSA keys. It can be used to convert generate, modify, and convert the DSA keys. To use the openssl dsa command, OpenSSL must be installed in Linux.

In this tutorial, we explained the openssl dsa command, its syntax, options, and usage through various examples.

Advertisements