Package: keysec
KeySecWith this program you'll be able to:Generate OpenSSL and OpenSSH private and public keys (Ed25519, RSA)Convert a key pair between both formats (OpenSSL ↔ OpenSSH)Add, edit and remove passphrases from private keys.Add, edit and remove comments from OpenSSH keys.See information about a key.You need to haveopensslandssh-keygenfor this program to work.Table of contentsInstallationHow to use itGenerate an Ed25519 key pairGenerate an RSA key pairChange a key pair formatEdit a key passphraseEdit a key commentShow information about a keyHelpPackagingAutopackage PortableAutopackage WheelPyInstallerContributingLicenseInstallationUse the package managerpiporpipxto install it:pipinstallkeysecAlternatively, you can use one of the two portable versions provided on the releases page.The lightest one has been packaged usingautopackageand will require you to have Python 3.9+ installed.The heavier one has been packaged usingPyInstallerand has no external dependencies, so it doesn't matter if you don't have Python installed, or if your version is
lower than 3.9.SeePackagingfor more information.How to use itThe program has very few options to keep it simple, so let's see some examples.Before we begin, let's point out that this program is capable of outputting its results to a file (--out/-o) or to standard output.
Similarly, it is capable of reading input data from a file (--in/-i) or from standard input.This feature gives the program versatility to use linux pipes, as we will see now.Generate a key pairGenerate an Ed25519 key pairLet's start creating the private key. For this example we are creating it in OpenSSL format. To make it in OpenSSH format simply replace the corresponding--formatargument:keysec gen priv --algo ed25519 --format openssl --out private.key
keysec gen pub --in private.key --out public.keyNote: The default algorithm is alreadyEd25519, and the default format is OpenSSL, so simply writingkeysec gen privwould be enough for the first line.As we can see, we must first create the private key and then generate the public one from it.In a single line, using pipes, this would be:keysec gen priv | tee private.key | keysec gen pub > public.keyGenerate an RSA key pairNow let's do the same with a 4096-bit RSA key pair (by default the program uses 2048 bits, and these are the only two options available), but this time we will generate them in OpenSSH formatkeysec gen priv --algo rsa --bits 4096 --format openssh --out private.key
keysec gen pub -i private.key -o public.keyIn a single line, using pipes, this would be:keysec gen priv -a rsa -b 4096 -f openssh | tee private.key | keysec gen pub -o public.keyChange a key pair formatEither if we have an OpenSSL or an OpenSSH key pair, we can perform transformations between both formats.If the original key has a passphrase, it will be kept in the new formatted one unless--nopass/-npis specified.Let's see three ways to use this command:keysec conv < keyfilekeysec conv -i keyfile --nopasscat keyfile | keysec conv -npThe program will automatically detect the original format and perform the transformation to the other one.Edit a key passphraseTo interactively add, edit or remove a private key passphrase, use the--password/-poption:keysec edit -p -i private.keyEdit a key commentIf you want to add, edit, or delete an OpenSSH public or private key comment, you can choose to do so interactively or put it in the arguments, as shown in the next two examples.For interactive mode, simply use the option--comment/-c:keysec edit --comment --in keyfileTo directly write the comment to the key without being prompted for input, just do:keysec edit -c "root@host" -i keyfileUse an empty string to remove a comment:keysec edit -c "" -i keyfileShow information about a keyShow some information about a private or public key. Again, like the last command, there is more than one way to do this. The simplest one is:keysec info < keyfileHelpThere are also multiple help options--help/-hin the program. Don't forget to read them if you forget something:keysec -h
keysec gen -h
keysec gen priv -h
keysec gen pub -h
keysec conv -h
keysec edit -h
keysec info -hPackagingIn this section we are going to explain how to replicate the packaging process.Autopackage PortableTo generate the program lightest portable version, which is available in this GitHub repository, install firstautopackagewithpip:pip install autopackageThen run the following commands:autopackage -s setup.py -pAutopackage WheelTo generate the program wheel, available at PyPi, first do the following:In thesetup.pyfile remove thepackage_datavariable and also remove it from theSetupParsercallIn thesetup.pyfile change thezip_safeflag toTrueIn the__main__.pyfile remove lines from5to20, that import the files inside thelibsfolder.Then run:autopackage -s setup.pyPyInstallerTo generate the program heaviest portable version, which is also available in this GitHub repository, installpyinstallerwithpip:pip install pyinstallerThen run:pyinstaller --onefile keysec.pyContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.LicenseThis program is licensed under theGNU General Public License v3 or later (GPLv3+)