One of the most common forms of cryptography today is public-key cryptography helps to communicate two system by encrypting information using the public key and information can be decrypted using private key. These keys are using mainly on login to server securely and also transferring data securely.
We can generate these private public keys by various ways.
Suppose you want to generate DSA key pairs. DSA. dsa = DSAnew; DSAgenerateparametersex(dsa,2048,NULL,0,NULL,NULL, NULL); DSAgeneratekey(dsa); Or use command line: openssl dsaparam -genkey 2048. Mar 12, 2014 How to Generate RSA,DSA keys using OpenSSL. Openssl tutorial generate rsa,dsa keys learn how to verify rsa,dsa keys.
with password encryption
Generate public key:
Download puttyGen from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html and run it.
Planetary annihilation steam key generator. You can select one of the key types, SSH-1, SSH-2, and SSH-2 DSA.
SSH-2 is probably better than others but you have to make sure if your system supports SSH-2, if your system ( server) doesnt support it then you better off with SSH-1.
Level of encryption can be set from “Number of bits in a generated key” . Security level can be enhance by using 2048 but again make sure where you are using it and thus follow the recommendation for this value. I prefer 2048 but even with 1024 is much more secure.
Click on generate to create keys. Move your mouse over the empty space to help puttygen to genereate random variables.
Once the key is generated you will see following window.
If you want to login without password ( in case of ssh login) you can put your passphase empty. click on Save Public key and Save private key to save your keys.
When you save private key it will be saved in ppk format which you can use putty to login to your system.
We can get private key for openSSH by clicking on Conversions->Export OpenSSH key
If you want to use ssh to login with these generated key / pair then
copy public key ( mykey.pub) to .ssh/authorized_key.
rsa
, dsa
, rsa1
, ed25519
or ecdsa
private keys.The below requirements are needed on the host that executes this module.
Parameter | Choices/Defaults | Comments |
---|---|---|
attributes string | The attributes the resulting file or directory should have. To get supported flags look at the man page for chattr on the target system. This string should contain the attributes in the same order as the one displayed by lsattr. The = operator is assumed as default, otherwise + or - operators need to be included in the string. | |
comment added in 2.9 | Provides a new comment to the public key. When checking if the key is in the correct state this will be ignored. | |
force boolean |
| Should the key be regenerated even if it already exists |
group string | Name of the group that should own the file/directory, as would be fed to chown. | |
mode string | The permissions the resulting file or directory should have. For those used to /usr/bin/chmod remember that modes are actually octal numbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like 0644 or 01777 ) or quote it (like '644' or '1777' ) so Ansible receives a string and can do its own conversion from string into number.Giving Ansible a number without following one of these rules will end up with a decimal number which will have unexpected results. As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, u+rwx or u=rw,g=r,o=r ).As of Ansible 2.6, the mode may also be the special string preserve .When set to preserve the file will be given the same permissions as the source file. | |
owner string | Name of the user that should own the file/directory, as would be fed to chown. | |
path path / required | Name of the files containing the public and private key. The file containing the public key will have the extension .pub . | |
selevel string | Default: | The level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the range .When set to _default , it will use the level portion of the policy if available. |
serole string | When set to _default , it will use the role portion of the policy if available. | |
setype string | When set to _default , it will use the type portion of the policy if available. | |
seuser string | By default it uses the system policy, where applicable.When set to _default , it will use the user portion of the policy if available. | |
size integer | Specifies the number of bits in the private key to create. For RSA keys, the minimum size is 1024 bits and the default is 4096 bits. Generally, 2048 bits is considered sufficient. DSA keys must be exactly 1024 bits as specified by FIPS 186-2. For ECDSA keys, size determines the key length by selecting from one of three elliptic curve sizes: 256, 384 or 521 bits. Attempting to use bit lengths other than these three values for ECDSA keys will cause this module to fail. Ed25519 keys have a fixed length and the size will be ignored. | |
state string |
| Whether the private and public keys should exist or not, taking action if the state is different from what is stated. |
type string |
| The algorithm used to generate the SSH private key. rsa1 is for protocol version 1. rsa1 is deprecated and may not be supported by every version of ssh-keygen. |
unsafe_writes boolean |
| Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target file. By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted files, which cannot be updated atomically from inside the container and can only be written in an unsafe manner. This option allows Ansible to fall back to unsafe methods of updating files when atomic operations fail (however, it doesn't force Ansible to perform unsafe writes). IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption. |
Common return values are documented here, the following are the fields unique to this module:
Key | Returned | Description |
---|---|---|
comment string | changed or success | Sample: |
filename | changed or success | Path to the generated SSH private key file /tmp/id_ssh_rsa |
fingerprint string | changed or success | Sample: SHA256:r4YCZxihVjedH2OlfjVGI6Y5xAYtdCwk8VxKyzVyYfM |
public_key string | changed or success | Sample: ssh-rsa AAAAB3Nza(..omitted..)veL4E3Xcw test_key |
size integer | changed or success | Sample: |
type | changed or success | Algorithm used to generate the SSH private key rsa |
Hint
If you notice any issues in this documentation, you can edit this document to improve it.