- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to generateencryptdecrypt random passwords in linux
Security is one of the major concern in the cyber world. Cyber security, also referred to as information technology security, focuses on protecting computers, networks, programs and data from unintended or unauthorized access, change or destruction. We use passwords for computers, emails, cloud, phone, documents and what not. We all know the basics of choosing a password that is easy to memorize and hard to guess. Still, If users want to encrypt or decrypt passwords, then Linux provides you lot of options.
This article describes “How to Generate/Encrypt/Decrypt Random Passwords in Linux”.
PWGen
PwGen is a random unique password generator. To install PWGen, use the following command –
$ sudo apt-get install pwgen
The sample output should be like this –
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: gcc-4.8-base:i386 libasn1-8-heimdal:i386 libasound2:i386 libasound2-plugins:i386 libasyncns0:i386 libavahi-client3:i386 libavahi-common-data:i386 libavahi-common3:i386 libbit-vector-perl libcapi20-3:i386 libcarp-clan-perl libclass-method-modifiers-perl libcups2:i386 libdata-random-perl libdate-calc-perl libdate-calc-xs-perl libdrm-amdgpu1:i386 libdrm-intel1:i386 libdrm-nouveau2:i386 libdrm-radeon1:i386 libedit2:i386 libelf1:i386 libexif12:i386 libexpat1:i386 libffi6:i386 libflac8:i386 libfontconfig1:i386 libfreetype6:i386 libgcrypt11:i386 libgd-perl libgd3:i386 libgif4:i386 libgl1-mesa-dri-lts-wily:i386 libgl1-mesa-glx-lts-wily:i386 libglapi-mesa-lts-wily:i386 libglib2.0-0:i386 libglu1-mesa:i386 libgnome2-gconf-perl libgnutls26:i386 libgpg-error0:i386 libgphoto2-6:i386 libgphoto2-port10:i386 libgssapi-krb5-2:i386 libgssapi3-heimdal:i386 libgstreamer-plugins-base0.10-0:i386 libgstreamer0.10-0:i386 libhcrypto4-heimdal:i386 libheimbase1-heimdal:i386 libheimntlm0-heimdal:i386 libhx509-5-heimdal:i386 libice6:i386 libieee1284-3:i386 libjack-jackd2-0:i386 libjbig0:i386 libjpeg-turbo8:i386 libjpeg8:i386 libk5crypto3:i386 libkeyutils1:i386 libkrb5-26-heimdal:i386 libkrb5-3:i386 libkrb5support0:i386 liblcms2-2:i386 libldap-2.4-2:i386 libllvm3.6:i386 libltdl7:i386 libmouse-perl libmpg123-0:i386 libnet-dropbox-api-perl ..........................................
To generate random unique password of length equal to 10 characters, use the following command –
$ pwgen 5 1
The sample output should be like this –
$ pwgen 10 1 lah6M
To generate several random unique passwords of character length 50, use the following command –
$ pwgen 50
The sample ouput should be like this –
$ pwgen 50 Meepahshoo4ee9kohvezah8fu0Ox0neogh9iechoo9thoocooM ye7ieliiGhief6ohquahf4leithei7sugh6shu3nooy6ooz7Ae ieng0shefaizeezoo6ila5Ecee0iu9aaquaiwie8chi1yoh4ah iiw7Noogh1hi5iga2queepheiCahyaghiesie2yaexeifeifoo lunu9Aic1iepah4Bei8wenee4aer1aiVaing1hoh7eiphiu1le kooquifooFai3uK7Gai8Ix9oph8oolah0ohp2iheiChaepudie caiTiem3ilies0nietetheevei2oatoeloh7iLooPi8Beeneey esug8ahmait6reepheaBoo8goequ2Bu9oodoo5rahkaeweequa nie4ahgheida2xiij6hak7ke5lu0ugh1otah7Feir8iefoDaum noy1chep2da3eu7sheicohZaighai8aem9feec8bohmei2eemu zu8Aec3Pei6ol2ahteexoc3goQuaisai4upaj5chepha6ahsh4 lah4aedahTee2ki6zou4uphoBoh5Ooyeixaihiu5fuoYah7Tei ooS6ku2Ia9Eilohchubais7yoxeephohS9Eath9Pequ3aengae Ooqui3goeko1loh6ooshaikiahi4noxaiDuiP2Ohruroh2ohba pa3quee7Lagheengae9iR3fooHooXa0Ioth0ieMee2pe2Ain9h maife3eiLerooh3to0eeGee6ahHo0aeT9Eef7axa7eiY4LaeP2 aech0AiWuoTheeGeno6NoWahgh0shish8quoo3Chu0uoxahmie paihay0aip3iexaseidah1OhRoo3Eeniemulah8oG7VobeaThi seequ2akooW6Teij2aico6aivohT3eshaeri0Gohjaigiohixu pee8eith4Rinodeequoh2Eipowuvool7ohquu8eibai4haih1h
makepasswd
makepasswd is used to generate random, unique password of given length as per choice. To install makepasswd, use the following command –
$ sudo apt-get install makepasswd
The sample output should be like this –
Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: gcc-4.8-base:i386 libasn1-8-heimdal:i386 libasound2:i386 libasound2-plugins:i386 libasyncns0:i386 libavahi-client3:i386 libavahi-common-data:i386 libavahi-common3:i386 libbit-vector-perl libcapi20-3:i386 libcarp-clan-perl libclass-method-modifiers-perl libcups2:i386 libdata-random-perl libdate-calc-perl libdate-calc-xs-perl libdrm-amdgpu1:i386 libdrm-intel1:i386 libdrm-nouveau2:i386 libdrm-radeon1:i386 libedit2:i386 libelf1:i386 libexif12:i386 libexpat1:i386 libffi6:i386 libflac8:i386 libfontconfig1:i386 libfreetype6:i386 libgcrypt11:i386 libgd-perl libgd3:i386 libgif4:i386 libgl1-mesa-dri-lts-wily:i386 libgl1-mesa-glx-lts-wily:i386 libglapi-mesa-lts-wily:i386 libglib2.0-0:i386 libglu1-mesa:i386 libgnome2-gconf-perl libgnutls26:i386 libgpg-error0:i386 libgphoto2-6:i386 libgphoto2-port10:i386 libgssapi-krb5-2:i386 libgssapi3-heimdal:i386 libgstreamer-plugins-base0.10-0:i386 libgstreamer0.10-0:i386 libhcrypto4-heimdal:i386 libheimbase1-heimdal:i386 libheimntlm0-heimdal:i386 libhx509-5-heimdal:i386 libice6:i386 libieee1284-3:i386 libjack-jackd2-0:i386 libjbig0:i386 libjpeg-turbo8:i386 libjpeg8:i386 libk5crypto3:i386 libkeyutils1:i386 libkrb5-26-heimdal:i386 libkrb5-3:i386 libkrb5support0:i386 liblcms2-2:i386 libldap-2.4-2:i386 libllvm3.6:i386 libltdl7:i386 libmouse-perl libmpg123-0:i386 libnet-dropbox-api-perl libogg0:i386 libopenal1:i386 liborc-0.4-0:i386 libosmesa6:i386 .........................................
To generate a random password of character length 10 (Default Value is 10), use the following command –
$ makepasswd
The sample output should be like this –
$ makepasswd c0CgufUg
To generate a random password of character length 50, use the following command –
$ makepasswd --char 40
The sample output should be like this –
$ makepasswd --char 50 HCvvXipXmc7idBcWHt8UcjcX21xvC9P700NgCAoM
To generate 10 random password of 20 characters, use the following command –
$ makepasswd --char 20 --count 10
The sample output should be like this –
$ makepasswd --char 20 --count 10 b8aotAGE83WqpNXb6tms XBItn0UenWhc4dNixcBD uE5Km8J8ssHIThhSBWnS XFcfA50Ew6iD0WxwsuKn 3e4nxDU0F3WtzLE7WNoV G640DxC3XsrFQRgFtHho THXKMI65qojzGCVsmje8 LmhK9ScX9uJCE2mDgEYD p9YU7eWI4CN9cxeiLUGn rraxYCpGUNjiFvXmNJha
To encrypt the password use mkpasswd command.installing mkpasswd as shown below –
$ sudo apt-get install whois
The sample output should be like this –
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: gcc-4.8-base:i386 libasn1-8-heimdal:i386 libasound2:i386 libasound2-plugins:i386 libasyncns0:i386 libavahi-client3:i386 libavahi-common-data:i386 libavahi-common3:i386 libbit-vector-perl libcapi20-3:i386 libcarp-clan-perl libclass-method-modifiers-perl libcups2:i386 libdata-random-perl libdate-calc-perl libdate-calc-xs-perl libdrm-amdgpu1:i386 libdrm-intel1:i386 libdrm-nouveau2:i386 libdrm-radeon1:i386 libedit2:i386 libelf1:i386 libexif12:i386 libexpat1:i386 libffi6:i386 libflac8:i386 libfontconfig1:i386 libfreetype6:i386 libgcrypt11:i386 libgd-perl libgd3:i386 libgif4:i386 libgl1-mesa-dri-lts-wily:i386 libgl1-mesa-glx-lts-wily:i386 libglapi-mesa-lts-wily:i386 libglib2.0-0:i386 libglu1-mesa:i386 libgnome2-gconf-perl libgnutls26:i386 libgpg-error0:i386 libgphoto2-6:i386 ......................................
To encrypt password using mkpasswd, use the following command –
$ mkpasswd tutorialspoint
The sample output should be like this –
$ mkpasswd tutorialspoint V8dIs6XzLXB7c
To encrypt the password using aes-256-cbc encryption, use the following command –
$ echo Tutorialspoint-is-a-best-online-resouce | openssl enc -aes-256-cbc -a -salt -pass pass:tutorialspoint
The sample output should be like this –
$ echo Tutorialspoint-is-a-best-online-resouce | openssl enc -aes-256-cbc -a -salt -pass pass:tutorialspoint U2FsdGVkX19TJ9x2yI18KoP1TzIbyCQhkrK8uShPTm3CtLaZpI4YkOQG3O8RcQnX wymb1bWnshJXkFeyATgCQw==
To decrypt the above string, use the following command –
$ echo U2FsdGVkX19TJ9x2yI18KoP1TzIbyCQhkrK8uShPTm3CtLaZpI4YkOQG3O8RcQnX | openssl enc -aes-256-cbc -a -d -salt -pass pass:tutorialspoint
The sample output should be like this –
Tutorialspoint-is-a-best-online-resouce
Congratulations! Now, you know “How to Generate/Encrypt/Decrypt Random Passwords in Linux”. We’ll learn more about these types of commands in our next Linux post. Keep reading!