Is there any way to put the password typed by user into a file (either in Unix or in expect).read -s -p enter password input echo $input > fileIs the above code safe?I want to use that file as an input for password in my expect scriptBecause I have tried this and I could see the password shown on the screen just for a sec with this expect code.set timeout 30stty -echosend_user -- Password for $username :expect_user -re (.*)\nset timeout .000000001set timeout 30send_user \nset timeout 30set password $expect_out(1,string)send -- $password\r
How to safely put user typed password into a file?
linux;shell script;password;expect
Whoever can read the file will get the password. That includes root, the user owning the file (or somebody impersonating them), and (depending on permissions) the users in the group or even everybody. Anyone who has a few minutes alone with the machine can reboot it with a LiveCD/LiveUSB and get at the file. And a long list of other possibilities. It is not safe. Perhaps enough for casual use, but not for anything serious. And consider that I don't think it is critical isn't enough, need to think any possible chain of uses of the privileges granted, other sites using the same password (or one constructed the same way), ...