{"id":16951,"date":"2023-08-21T06:00:38","date_gmt":"2023-08-21T06:00:38","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=16951"},"modified":"2024-01-18T12:08:24","modified_gmt":"2024-01-18T12:08:24","slug":"bash-read-password","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/","title":{"rendered":"How to Read Password in Bash [3 Practical Cases]"},"content":{"rendered":"<p style=\"text-align: justify;\">Taking a user password in Bash is an important task. One can utilize the <strong>read<\/strong> command to read passwords securely. Moreover, the <strong>openssl<\/strong> command provides the opportunity to encrypt passwords in an irreversible way. This article discusses three different cases of how to read a user password in Bash considering its security concern.<\/p>\n<div class=\"su-youtube su-u-responsive-media-yes\"><iframe width=\"600\" height=\"400\" src=\"https:\/\/www.youtube.com\/embed\/lVVfOz-vCuM?\" frameborder=\"0\" allowfullscreen allow=\"autoplay; encrypted-media; picture-in-picture\" title=\"\"><\/iframe><\/div>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/Practice-Files_bash-read-password.zip\" class=\"su-button su-button-style-default\" style=\"color:#000000;background-color:#E8F9FF;border-color:#bac8cc;border-radius:56px\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color:#000000;padding:8px 26px;font-size:20px;line-height:30px;border-color:#effbff;border-radius:56px;text-shadow:0px 0px 0px #000000\"><i class=\"sui sui-download\" style=\"font-size:20px;color:#1AA1D6\"><\/i>  Practice Files to Read Password in Bash<\/span><\/a><\/div>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#3_Cases_of_Reading_Password_in_Bash\" >3 Cases of Reading Password in Bash<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#Case_1_Reading_Password_From_Prompt\" >Case 1: Reading Password From Prompt<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#Case_2_Reading_Password_Without_Displaying_It_to_the_User_in_Bash\" >Case 2: Reading Password Without Displaying It to the User in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#Case_3_Reading_Password_From_a_Password_File\" >Case 3: Reading Password From a Password File<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#Echoing_Asterisk_for_Each_Character_while_Reading_Password\" >Echoing * (Asterisk) for Each Character while Reading Password<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#How_to_Encrypt_Password_Using_Hash_Algorithm_in_Bash\" >How to Encrypt Password Using Hash Algorithm in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#People_Also_Ask\" >People Also Ask<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#How_to_read_in_bash_script\" >How to read in bash script?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#How_to_save_password_into_environment_variable\" >How to save password into environment variable?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#Does_-s_option_of_read_command_is_used_to_take_input_in_a_new_line\" >Does -s option of read command is used to take input in a new line?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#Why_do_you_need_to_read_user_password_in_Bash\" >Why do you need to read user password in Bash?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"3_Cases_of_Reading_Password_in_Bash\"><\/span>3 Cases of Reading Password in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">The <strong>read<\/strong> command is commonly used to gather user input. Similarly, it&#8217;s handy for reading passwords while keeping them hidden with the <strong>-s<\/strong> option. Moreover one can read passwords from files. Let&#8217;s explore different scenarios of reading passwords in Bash.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Case_1_Reading_Password_From_Prompt\"><\/span>Case 1: Reading Password From Prompt<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The common approach to reading a password is by prompting the requirement of the password to the user. In the following script, I will show you how to read the user password from the prompt using the <strong>read <\/strong>command.<\/p>\n<p>To read a password by prompting to the user, please see the following bash script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Prompt the user for a password\nread -p &quot;Enter your password: &quot; password\necho\u00a0 # Move to a new line after reading the password\n\n# Read the new username\nread -p &quot;Enter the username to add: &quot; new_username\n# Use sudo to add a new user\necho &quot;$password&quot; | sudo -S useradd &quot;$new_username&quot;\n\n# Check if the user was added successfully\nif [ $? -eq 0 ]; then\necho &quot;User $new_username added successfully&quot;\nelse\necho &quot;Failed to add user $new_username&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">The script prompts the user to enter the password using the <strong>read<\/strong> command. Then the user is prompted to provide a username for the new account. The script then employs the <a href=\"https:\/\/linuxsimply.com\/sudo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>sudo command<\/strong><\/a>, along with the provided password, to add a user using the <strong>useradd command<\/strong>. Finally, it displays a confirmation message based on the exit status of the <strong>useradd <\/strong>command.<\/div><\/div>\n<p style=\"text-align: justify;\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-16955 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Reading-password-from-user-prompt.png\" alt=\"Read password from user prompt\" width=\"825\" height=\"191\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Reading-password-from-user-prompt.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Reading-password-from-user-prompt-300x69.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Reading-password-from-user-prompt-765x177.png 765w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/>The image shows that the program first seeks the password of the user which is given as <strong>Ubuntu<\/strong>. Then it executes commands for adding a new user using the given <strong>password<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Case_2_Reading_Password_Without_Displaying_It_to_the_User_in_Bash\"><\/span>Case 2: Reading Password Without Displaying It to the User in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The <strong>read<\/strong> command can be employed to capture a user&#8217;s password without displaying it on the screen. This approach adds an extra layer of protection and keeps passwords hidden from others&#8217; sight. The <code class=\"\" data-line=\"\">-s<\/code> option of the <strong>read<\/strong> command is used for this purpose.<\/p>\n<p>To read a password in a hidden manner, use the Bash script below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n# Prompt the user for a password\nread -p -s &quot;Enter your password: &quot; password\necho  # Move to a new line after reading the password\n\n# Read the new username\nread -p &quot;Enter the username to add: &quot; new_username\n\n# Use sudo to add a new user\necho &quot;$password&quot; | sudo -S useradd &quot;$new_username&quot;\n\n# Check if the user was added successfully\nif [ $? -eq 0 ]; then\n  echo &quot;User $new_username added successfully&quot;\nelse\n  echo &quot;Failed to add user $new_username&quot;\nfi\n<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">The script prompts the user to input a password using the <strong>-s<\/strong> flag, ensuring the password remains unrevealed on the screen. Subsequently, the script prompts for a username. The provided password is then used to execute the <code class=\"\" data-line=\"\">sudo -S useradd<\/code> command, adding the new user with the specified username. Finally, it displays a confirmation message based on the exit status of the <strong>useradd <\/strong>command whether the new user is created successfully or not.<\/div><\/div>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-16954\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/2.-Changing-permission-of-Bash-script-file.png\" alt=\"Changing permission of Bash script file\" width=\"825\" height=\"170\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/2.-Changing-permission-of-Bash-script-file.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/2.-Changing-permission-of-Bash-script-file-300x62.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/2.-Changing-permission-of-Bash-script-file-767x158.png 767w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/>You can see that the user <strong>Bin <\/strong>is created successfully after reading the system password from the current user. However, the given password is not displayed while reading it from the user. The\u00a0 <strong>-s <\/strong>option of the <strong>read<\/strong> command successfully hides the password.<\/p>\n<div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#E8F9FC;border-color:#ffffff;color:#333333;\">\n<p style=\"text-align: justify;\"><strong>NOTE:<\/strong> You can achieve a similar effect using the <strong>stty <\/strong>command. It can control terminal settings and hide user input from the terminal. For example, <strong>stty -echo <\/strong>will hide user input while using the <strong>read <\/strong>command. <\/div><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Case_3_Reading_Password_From_a_Password_File\"><\/span>Case 3: Reading Password From a Password File<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Imagine having a password file where you&#8217;ve stored all your passwords. Instead of inputting the password manually through a prompt, a program can retrieve it directly from the saved file. Let\u2019s see how it works.<\/p>\n<p style=\"text-align: justify;\">To read a password from a password file, please go through the below script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nfile=&quot;password.txt&quot;\n# Use &#039;grep&#039; to find the password\npassword=$(grep &quot;Linux :&quot; &quot;$file&quot; | awk -F &#039;: &#039; &#039;{print $2}&#039;)\n\n# Check if the password was found\nif [ -z &quot;$password&quot; ]; then\necho &quot;Password not found.&quot;\nexit 1\nelse\necho &quot;System successfully finds the password.&quot;\nfi\n\n# Read the new username\nread -p &quot;Enter the username to add: &quot; new_username\n# Use sudo to add a new user with the extracted password\necho &quot;$password&quot; | sudo -S useradd &quot;$new_username&quot;\n\n# Check if the user was added successfully\nif [ $? -eq 0 ]; then\necho &quot;User $new_username added successfully&quot;\nelse\necho &quot;Failed to add user $new_username&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">This Bash script reads the content of the <strong>password.txt<\/strong> file and attempts to find a password associated with <strong>Linux<\/strong>. It uses the <a href=\"https:\/\/linuxsimply.com\/grep-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>grep command<\/strong><\/a> to search for a line containing &#8220;Linux :&#8221; and then employs <a href=\"https:\/\/linuxsimply.com\/awk-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>awk<\/strong><\/a> to extract the password field following the colon.<\/p>\n<p style=\"text-align: justify;\">The script utilizes the extracted password as input to the <code class=\"\" data-line=\"\">sudo -S useradd<\/code> command, attempting to add a new user with the specified username using the extracted password.<\/p>\n<p style=\"text-align: justify;\">After the user addition attempt, the script checks the exit status of the <strong>useradd<\/strong> command. If the exit status is <strong>0<\/strong>, it prints a success message indicating that the user was added; otherwise, it prints a failure message.<\/div><\/div>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-16957\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/5.-File-with-password.png\" alt=\"File with password\" width=\"539\" height=\"273\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/5.-File-with-password.png 539w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/5.-File-with-password-300x152.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/5.-File-with-password-766x388.png 766w\" sizes=\"(max-width: 539px) 100vw, 539px\" \/>As you can see there are passwords for various applications stored in the <strong>password.txt<\/strong> file. The password for <strong>Linux <\/strong>is in the third line of the file.<\/p>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-16958\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/6.-Reading-password-from-file.png\" alt=\"Reading password from file\" width=\"661\" height=\"192\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/6.-Reading-password-from-file.png 661w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/6.-Reading-password-from-file-300x87.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/6.-Reading-password-from-file-768x223.png 768w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/>See the output image, the program reads the password of <strong>Linux <\/strong>from the file. Using this password it successfully added a new user <strong>Jemmy <\/strong>to the system.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Echoing_Asterisk_for_Each_Character_while_Reading_Password\"><\/span>Echoing * (Asterisk) for Each Character while Reading Password<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Someone may be confused whether a program takes a password or not if nothing is displayed on the <strong>terminal<\/strong>. So, instead of displaying nothing one can use the following script to display an <strong>asterisk<\/strong> for each inputted character of the password:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\npassword=&quot;&quot;\nprompt=&quot;Enter your password: &quot;\n\nwhile IFS= read -p &quot;$prompt&quot; -r -s -n 1 letter; do\nif [[ $letter == $&#039;\\0&#039; ]]; then\nbreak\nfi\npassword=&quot;$password$letter&quot;\nprompt=&quot;*&quot;\ndone\n\necho -e &quot;\\nPassword entered: $password&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">The script initializes an empty <strong>password<\/strong> variable and seeks the password from the user. Then it enters in a <strong>while loop<\/strong> where the <strong>read<\/strong> command is used to capture individual characters of user input.<\/p>\n<p style=\"text-align: justify;\"><code class=\"\" data-line=\"\">-r -s -n 1<\/code> ensures that the input is read silently by avoiding backslashes and reading only a single character at a time. An asterisk is displayed for each appended character to the password variable.<\/div><\/div>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-16959\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/7.-Echoing-asterisk-while-taking-password.png\" alt=\"Echoing asterisk while taking password\" width=\"497\" height=\"160\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/7.-Echoing-asterisk-while-taking-password.png 497w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/7.-Echoing-asterisk-while-taking-password-300x97.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/7.-Echoing-asterisk-while-taking-password-767x247.png 767w\" sizes=\"(max-width: 497px) 100vw, 497px\" \/>As evident, the script displays asterisks to validate each user input. In this instance, the user entered <strong>Ubuntu<\/strong> as the password, resulting in the display of <strong>six<\/strong> asterisks. This pattern confirms to the user that their input has been accurately captured.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Encrypt_Password_Using_Hash_Algorithm_in_Bash\"><\/span>How to Encrypt Password Using Hash Algorithm in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">You can encrypt passwords using the <strong>openssl <\/strong>command for public servers. It uses various hash algorithms such as the <strong>SHA-256<\/strong> algorithm and a randomly generated salt to encrypt a password. Hashing is a one-way function. It means that once a password is hashed, it isn\u2019t easy to convert it back to the original.<\/p>\n<p>To encrypt passwords using the hash algorithm in bash, see the below script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Generate a random salt\nsalt=$(openssl rand -base64 8)\n\n# Get the password from the user\nread -p &quot;Enter your password: &quot; password\n\n# Combine the password and salt, then hash using SHA-256\nhashed_password=$(echo -n &quot;$password$salt&quot; | openssl dgst -sha256 -binary | base64)\n\necho &quot;Salt: $salt&quot;\necho &quot;Hashed Password: $hashed_password&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">In this Bash script, a random <strong>8-byte<\/strong> salt is generated using the <strong>openssl<\/strong> command. The user is prompted to input a password. The script then combines the user&#8217;s <strong>password<\/strong> and the generated <strong>salt<\/strong>.<\/p>\n<p style=\"text-align: justify;\">This concatenated string is hashed using the <strong>SHA-256<\/strong> algorithm through the <strong>openssl dgst<\/strong> command. The resulting binary hash is then encoded in <strong>base64<\/strong> format to generate the final hashed password.<\/div><\/div>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16960 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/8.-Encrypt-password-using-a-hash-algorithms.png\" alt=\"Encrypt password using a hash algorithms in bash\" width=\"825\" height=\"166\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/8.-Encrypt-password-using-a-hash-algorithms.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/8.-Encrypt-password-using-a-hash-algorithms-300x60.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/8.-Encrypt-password-using-a-hash-algorithms-765x154.png 765w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/>Here the password <strong>Ubuntu<\/strong> is hashed using <strong>openssl<\/strong> command. The encrypted password is displayed in the image above.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In conclusion, one can read a user password in Bash in various ways with different layers of protection. Moreover, one can store encrypted passwords using hash-based algorithms. I believe from now on you can take user passwords securely as well as encrypt passwords where necessary.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"People_Also_Ask\"><\/span>People Also Ask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"How_to_read_in_bash_script\"><\/span>How to read in bash script?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To read user input in the Bash script, you can simply use the <code class=\"\" data-line=\"\">read<\/code> command. It takes input from the user and assigns it to the variable. You can also use the <code class=\"\" data-line=\"\">-p<\/code> option of the read command to provide a prompt to the user directly.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_save_password_into_environment_variable\"><\/span>How to save password into environment variable?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To save the password in any of the environment variables use the <strong>export<\/strong> command. For that, use the syntax, <code class=\"\" data-line=\"\">export MY_PASSWORD=&quot;your_password_here&quot;<\/code>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Does_-s_option_of_read_command_is_used_to_take_input_in_a_new_line\"><\/span>Does -s option of read command is used to take input in a new line?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><strong>No<\/strong>. The <code class=\"\" data-line=\"\">-s<\/code> option of the <code class=\"\" data-line=\"\">read<\/code> command is used to take input securely without displaying it to the <strong>terminal<\/strong>. To take user input in a new line use <code class=\"\" data-line=\"\">-n<\/code> option not <code class=\"\" data-line=\"\">-s<\/code>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Why_do_you_need_to_read_user_password_in_Bash\"><\/span>Why do you need to read user password in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Reading user passwords is needed for various actions in <strong>Bash<\/strong>. For example, if you want to install new packages or add new users via the <strong>sudo<\/strong> command then reading user passwords becomes essential for granting root privileges.<\/p>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"How to read in bash script?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To read user input in the Bash script, you can simply use the read command. It takes input from the user and assigns it to the variable. You can also use the -p option of the read command to provide a prompt to the user directly.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Does -s option of read command is used to take input in a new line?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"No. The -s option of the read command is used to take input securely without displaying it to the terminal. To take user input in a new line use -n option not -s.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Why do you need to read user password in Bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Reading user passwords is needed for various actions in Bash. For example, if you want to install new packages or add new users via the sudo command then reading user passwords becomes essential for granting root privileges.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"How to save password into environment variable?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To save the password in any of the environment variables use the export command. For that, use the syntax, export MY_PASSWORD=\\\"your_password_here\\\".\"\n    }\n  }]\n}\n<\/script><\/p>\n<p><span style=\"font-size: 18pt; color: #003366;\"><strong>Related Articles<\/strong><\/span><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/get-date\/\" target=\"_blank\" rel=\"noopener\">How to Get Date in Bash [2 Methods with Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/print-time\/\" target=\"_blank\" rel=\"noopener\">How to Print Time in Bash [2 Quick Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-users\/\" target=\"_blank\" rel=\"noopener\">How to List Users in Bash [2 Easy Ways]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/current-time\/\" target=\"_blank\" rel=\"noopener\">How to Get Current Time in Bash [4 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/date-format\/\" target=\"_blank\" rel=\"noopener\">How to Use Date Format in Bash [5 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/get-timestamp\/\" target=\"_blank\" rel=\"noopener\">How to Get Timestamp in Bash [2 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/copy-paste\/\" target=\"_blank\" rel=\"noopener\">How to Copy and Paste in Bash [2 Methods &amp; Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/send-email\/\" target=\"_blank\" rel=\"noopener\">How to Send Email in Bash [2 Easy Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/send-email-with-attachment\/\" target=\"_blank\" rel=\"noopener\">Bash Script to Send Email with Attachment [Step-by-Step Guide]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/get-ip-address\/\" target=\"_blank\" rel=\"noopener\">How to Get IP Address in Bash [3 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/find-and-replace\/\" target=\"_blank\" rel=\"noopener\">How to Find and Replace String in Bash [5 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/get-script-name\/\" target=\"_blank\" rel=\"noopener\">How to Get Script Name Using Bash Script? [3 Easy Ways]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/call-another-script\/\" target=\"_blank\" rel=\"noopener\">How to Call Another Script in Bash [2 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/generate-uuid\/\" target=\"_blank\" rel=\"noopener\">How to Generate UUID in Bash [3 Simple Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/write-to-file\/\" target=\"_blank\" rel=\"noopener\">3 Easy Ways to Write to a File in Bash Script<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/output-to-file\/\" target=\"_blank\" rel=\"noopener\">How to Write the Output to a File in Bash Script [5 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/list-in-bash\/\" target=\"_blank\" rel=\"noopener\">How to Create a List in Bash Scripts? [2 Easy Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/clear-history\/\" target=\"_blank\" rel=\"noopener\">How to Clear History in Bash [2 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/clear-screen\/\" target=\"_blank\" rel=\"noopener\">How to Clear Screen Using Bash Script? [2 Effective Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/check-ubuntu-version\/\" target=\"_blank\" rel=\"noopener\">How to Check Ubuntu Version Using Bash Scripts? [2 Methods]<\/a><\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>&lt;&lt; Go Back to <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;28 Essential Bash Script Examples&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1065857,&quot;3&quot;:{&quot;1&quot;:0},&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/\" target=\"_blank\" rel=\"noopener\">Bash Script Examples<\/a> <\/span>| <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Scripting Basics&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:16768,&quot;10&quot;:1,&quot;11&quot;:4,&quot;17&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Basics<\/a><\/span>\u00a0| <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Tutorial<\/a><\/strong><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;16951&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;How to Read Password in Bash [3 Practical Cases]&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\">Rate this post<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Taking a user password in Bash is an important task. One can utilize the read command to read passwords securely. &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Read Password in Bash [3 Practical Cases]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#more-16951\" aria-label=\"Read more about How to Read Password in Bash [3 Practical Cases]\">Read more<\/a><\/p>\n","protected":false},"author":314903,"featured_media":16952,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[114],"class_list":["post-16951","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-bash-script-examples","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Read Password in Bash [3 Practical Cases]<\/title>\n<meta name=\"description\" content=\"Reading password in Bash is an important task. This article talks about how to read password in Bash depending on security concern.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Read Password in Bash [3 Practical Cases]\" \/>\n<meta property=\"og:description\" content=\"Reading password in Bash is an important task. This article talks about how to read password in Bash depending on security concern.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/zahidlaku72\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-21T06:00:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-18T12:08:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/bash-read-password.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Md Zahidul Islam Laku\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Md Zahidul Islam Laku\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/\"},\"author\":{\"name\":\"Md Zahidul Islam Laku\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/26b37b2c7517d2c8702472bc3986ef21\"},\"headline\":\"How to Read Password in Bash [3 Practical Cases]\",\"datePublished\":\"2023-08-21T06:00:38+00:00\",\"dateModified\":\"2024-01-18T12:08:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/\"},\"wordCount\":1551,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/bash-read-password.png\",\"keywords\":[\"bash script examples\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/\",\"name\":\"How to Read Password in Bash [3 Practical Cases]\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/bash-read-password.png\",\"datePublished\":\"2023-08-21T06:00:38+00:00\",\"dateModified\":\"2024-01-18T12:08:24+00:00\",\"description\":\"Reading password in Bash is an important task. This article talks about how to read password in Bash depending on security concern.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/bash-read-password.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/bash-read-password.png\",\"width\":400,\"height\":400,\"caption\":\"bash read password\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/read-password\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash Scripting Tutorial\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Bash Scripting Basics\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Bash Script Examples\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/examples\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to Read Password in Bash [3 Practical Cases]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"name\":\"LinuxSimply\",\"description\":\"All About Linux\",\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linuxsimply.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\",\"name\":\"LinuxSimply\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"width\":355,\"height\":48,\"caption\":\"LinuxSimply\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/26b37b2c7517d2c8702472bc3986ef21\",\"name\":\"Md Zahidul Islam Laku\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"caption\":\"Md Zahidul Islam Laku\"},\"description\":\"Hey, I'm Zahidul Islam Laku currently working as a Linux Content Developer Executive at SOFTEKO. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). I write articles on a variety of tech topics including Linux. Learning and writing on Linux is nothing but fun as it gives me more power on my machine. What can be more efficient than interacting with the Operating System without Graphical User Interface! Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/zahidlaku72\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/zahidlaku\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCnxMIaAb-nXO5XnMeEaNhpQ\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/laku\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Read Password in Bash [3 Practical Cases]","description":"Reading password in Bash is an important task. This article talks about how to read password in Bash depending on security concern.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/","og_locale":"en_US","og_type":"article","og_title":"How to Read Password in Bash [3 Practical Cases]","og_description":"Reading password in Bash is an important task. This article talks about how to read password in Bash depending on security concern.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/zahidlaku72","article_published_time":"2023-08-21T06:00:38+00:00","article_modified_time":"2024-01-18T12:08:24+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/bash-read-password.png","type":"image\/png"}],"author":"Md Zahidul Islam Laku","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Md Zahidul Islam Laku","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/"},"author":{"name":"Md Zahidul Islam Laku","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/26b37b2c7517d2c8702472bc3986ef21"},"headline":"How to Read Password in Bash [3 Practical Cases]","datePublished":"2023-08-21T06:00:38+00:00","dateModified":"2024-01-18T12:08:24+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/"},"wordCount":1551,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/bash-read-password.png","keywords":["bash script examples"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/","name":"How to Read Password in Bash [3 Practical Cases]","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/bash-read-password.png","datePublished":"2023-08-21T06:00:38+00:00","dateModified":"2024-01-18T12:08:24+00:00","description":"Reading password in Bash is an important task. This article talks about how to read password in Bash depending on security concern.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/bash-read-password.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/bash-read-password.png","width":400,"height":400,"caption":"bash read password"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/read-password\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxsimply.com\/"},{"@type":"ListItem","position":2,"name":"Bash Scripting Tutorial","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/"},{"@type":"ListItem","position":3,"name":"Bash Scripting Basics","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/"},{"@type":"ListItem","position":4,"name":"Bash Script Examples","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/examples\/"},{"@type":"ListItem","position":5,"name":"How to Read Password in Bash [3 Practical Cases]"}]},{"@type":"WebSite","@id":"https:\/\/linuxsimply.com\/#website","url":"https:\/\/linuxsimply.com\/","name":"LinuxSimply","description":"All About Linux","publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxsimply.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linuxsimply.com\/#organization","name":"LinuxSimply","url":"https:\/\/linuxsimply.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","width":355,"height":48,"caption":"LinuxSimply"},"image":{"@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/26b37b2c7517d2c8702472bc3986ef21","name":"Md Zahidul Islam Laku","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","caption":"Md Zahidul Islam Laku"},"description":"Hey, I'm Zahidul Islam Laku currently working as a Linux Content Developer Executive at SOFTEKO. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). I write articles on a variety of tech topics including Linux. Learning and writing on Linux is nothing but fun as it gives me more power on my machine. What can be more efficient than interacting with the Operating System without Graphical User Interface! Read Full Bio","sameAs":["https:\/\/www.facebook.com\/zahidlaku72","https:\/\/www.linkedin.com\/in\/zahidlaku\/","https:\/\/www.youtube.com\/channel\/UCnxMIaAb-nXO5XnMeEaNhpQ"],"url":"https:\/\/linuxsimply.com\/author\/laku\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/16951","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/users\/314903"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=16951"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/16951\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/16952"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=16951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=16951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=16951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}