Visit Our UNIX and Linux User Community


Password hiding in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Password hiding in UNIX
# 1  
Old 08-07-2013
Password hiding in UNIX

Hi guys,

I use STTY command to make the password invisible.

Now I need to write the password into another file pwd.txt, but in an invisible manner, something like ******. Another thing is to when I echo the content of pwd.txt I get the password I actually typed.

Thanks guys. Help me out.

Last edited by Scott; 08-07-2013 at 10:30 AM.. Reason: ssty -> STTY; other spelling, grammar errors
# 2  
Old 08-07-2013
May be I'm wrong; your requirement looks ambiguous to me. If you want to write the password to a file in an "invisible manner something like ******", then how good (or secure) is it, if you are able to echo the content of pwd.txt and you get the password that you actually typed?
# 3  
Old 08-07-2013
hi thank u,
i am not sure about the second thing which i gave i.e to display,
but i need to write as ***** if i enter the password into file
# 4  
Old 08-07-2013
If you need to write the password to a file as "*****" just write a literal "*****" to the file. So long as you know there's no way to read it back as the entered password!

Here's something to display "*" as you type a password:
Code:
trap 'stty "$oldstty"; exit' 0

readString () {
  printf "Enter password: "
  oldstty=$(stty -g)
  stty -icanon -echo min 1 time 0
  while :; do
    K=$(dd bs=1 count=1 2>/dev/null) 
    [ ! "$K" ] && break
    S=$S$K
    printf "%c" ${K:+\*}
  done
  stty "$oldstty"
  echo
}

readString
echo "You entered: $S"

A variation on this old post: https://www.unix.com/302494498-post3.html
These 2 Users Gave Thanks to Scott For This Post:
# 5  
Old 08-08-2013
To Scott,

I have dreamed of such a function. Wonderful.


To mohanalakshmi,

Are you wanting to somehow encrypt the password and store it in a file? If so, you need to think of how you are going to mix it up and how you are going to reverse it. Maybe we can help with that, but you jhave to consider how you make the method secure. If someone can read the file and gets the string Krfmase7fjh!kwern and can read you code on how to reverse it, then the can manually follow the process. Even if you convert it to unprintable characters, then they could still use od to get the character codes and work from there.

If your decrypting script does something like this:-
  1. Read access encrypted password from file
  2. Decrypt value and feed to another command in plain text
..... then the above is a problem. If your logic follows more that:-
  1. You store the encrypted password
  2. Another process has to check the user password by encrypting and matching the stored value
... then this may be better, however if you code continues by doing something obvious because the password check is confirmed, then if they can read your code, they can just do the same but exclude the password checking. Consider:-
Code:
read passwd?"What is the password? "
check_password $passwd
if [ $? = 0 ]      # True returned from check_password function for accepted password
then
   vi /data_dir/payroll_file
else
   echo "You are not authorised!"
fi

There is nothing to stop a user reading this and just running vi /data_dir/payroll_file

What are you actually trying to achieve?



Robin
Liverpool/Blackburn
UK
# 6  
Old 10-14-2013
1. If you are a root and you trying to hide the password from other users, give 400 permission to that flat file.
2. If you have a DB available, create a table and store the password into it rather having that in a flat file.
3. Try your own encoding algorithm something like this. convert your passwd into some code, store it and decode with your logic again.
Code:
echo '73 61 74 68 79 61' |  perl -nE 'say map(chr, map { hex } split)'
sathya


Previous Thread | Next Thread
Test Your Knowledge in Computers #913
Difficulty: Medium
In bash, grep -v -e '^[[:space:]]*$' filename.txt will filter all the blank lines from filename.txt and display the results.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remote call not hiding password fields

Not sure on the description, but here is a quick rundown. I have 2 servers, we'll call them serverA serverB On serverB, I am calling a script that inside it has the following: ssh srvdsadm@serverB sudo -u dsadm /opt/apps/DataStage/scripts/autoDeploy.sh ${projName} ${subProjVar}... (1 Reply)
Discussion started by: cbo0485
1 Replies

2. Shell Programming and Scripting

Scripting help/advise on hiding/masking username/password

Hi, I currently have a UNIX script with a function that uses a username and password to connect to the database, retrieve some information and then exit. At the moment, am getting the username and password from a hidden plain text file and permission set to -r--------, i.e. read only to who... (1 Reply)
Discussion started by: newbie_01
1 Replies

3. Programming

C++ overriding Vs hiding

class B { public: void fns(void){//base def;} }; class D:public B { public: void fns(void) {//new def;} }; I was thinking the above is overriding but somewhere else i found the above is just hiding.Only virtual functions can be considered as overriding? This is the exact statement ... (1 Reply)
Discussion started by: johnbach
1 Replies

4. UNIX for Dummies Questions & Answers

New Approach Hiding login password from ps -ef

Hello all , I looked up this site for solutions to hide login info from ps -ef | grep like using a seperate file and store the password in that especially for oracle sqlplus scripts. I just got this thought , But dont know how to implement this in UNIX. Is there a way to revoke access from... (17 Replies)
Discussion started by: simonsimon
17 Replies

5. UNIX for Dummies Questions & Answers

Hiding Password

Hello. A bit of a puzzle here: I have a 3rd party executable, which requires the following parameters: parm1 = program_name, parm2=userid/password, parm3=additional flags. We tried passing password as a variable, but you can do grep, and see what the password actually is I found a bit... (2 Replies)
Discussion started by: Kishinevetz
2 Replies

6. Shell Programming and Scripting

Hiding password for FTP in a script

Hi, I have a simple script to ftp from unix to a mainframe to get and put files. Currently I have the password setup in a VARS file and dereference the var in my script. Doing it this way allws me to change the password in only one place but it is still viewable for many people. Is there any... (6 Replies)
Discussion started by: Cass3
6 Replies

7. UNIX for Advanced & Expert Users

Hiding files in unix/linux

Can Anybody please help me with the command in Unix/Linux which can help me hide the files which is equal to ATTRIB in DOS Not using . , but any commands in unix which will do this if you any script which will do this ,it will be very helpful Its very URGENT Regards Victor (9 Replies)
Discussion started by: victorvvk
9 Replies

8. UNIX for Dummies Questions & Answers

Hiding login/password in process!

Hello, I am trying to figure out away to hide a command from users when performing a ps check. I have a ksh that purges a table in a database. If I perform a >ps -eaf |grep ksh, I get the login id and password. I do not want other users seeing this. Is there a way to hide this. The login... (5 Replies)
Discussion started by: ctcuser
5 Replies

9. IP Networking

Hiding an IP address

Is there anyone who knows how to hide an IP from being logged by the site you are visiting. I know of some paid companies but I am looking for a different solution. Is there some way in UNIX to mask the ip. Help this is urgent. Datopdog (1 Reply)
Discussion started by: datopdog
1 Replies

10. Shell Programming and Scripting

Hiding password from ps

I'm calling a program with a command line arguement containing a password. while the process is running anyone on the system can ps -ef and see the password. Is there a way to prevent this from happening. example PROGRAM USERNAME/PASSWD I've also tried PROGRAM `cat passfile` ... (7 Replies)
Discussion started by: sudojo
7 Replies

Featured Tech Videos