Create a password generator using shell scripting

Creating a strong password is often a time-consuming task and even after creating a good password by yourself it gets brute-forced by hackers. In this article, we will learn how to create a strong password which fulfills all requirements including symbols, capitals length etc using a simple shell script in Linux.

How to create a password generator using shell script ?
This a simple short and quick method, just open the nano editor with .sh file using this command –

nano passwdgen.sh

You can use any name of the file.

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/bin/bash
  
# this can be anything of your choice
echo "Welcome to simple password generator" 
  
# ask the user how much long should be
echo "please enter the length of the password"  
  
# read the input given by user and store in variable
read  PASS_LENGTH 
  
# loop will create 5 passwords according to
# user as per length given by user                        
for p in $(seq 1 5);                                   
do 
    openssl rand -base64 48 | cut -c1-$PASS_LENGTH 
done

chevron_right


Save the file and give executable permission using sudo chmod +x command and run the script.

Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.