Learn howto password protect file in HPUX. This is helpful to encrypt some public readable files using password and decrypt them whenever needed.
Its pretty obvious that you can control file access using permissions but sometimes you may want to protect file lying in public directory like
/tmp with password of your choice. Or sometimes you may want even root shouldn’t read your files 😉
In that case you can use
crypt command to encrypt your file with password of your choice. This command is available in HPUX, Solaris. I couldn’t found it in Linux though.
crypt command is basically used to encrypt or decrypt file. So basically you will be encrypting your file with key of your choice and whenever you want to read it back, you need to decrypt it by supplying password/key you chose at the time of encryption.
Locking / encrypting file with key
Lets take a
myfile.txt sample file for encryption. You need to supply this file as a input to
crypt command and define output file (see example below).
# cat myfile.txt This is test file for crypt. # crypt < myfile.txt > myfile.crypt Enter key: # cat myfile.crypt 3▒▒▒x▒▒X▒n▒d▒6▒▒=▒▒q▒j
crypt command will ask you for a key. Its a password you can set of your choice. Note that, it wont ask you to re type key. Once executed you can new output file created (with name given in command). This file is encrypted and cant be read using
more etc commands!
Thats it! your file in encrypted. Now you can safely delete your original file
myfile.txt and keep encrypted copy on machine.
Unlocking / decrypting file with key
Now, to retrieve file content back i.e. decryption of file you can run same command. Only input and output file names will be exchange their positions. Now, encrypted filename will be your input file and original filename will be output file name.
# rm myfile.txt # crypt < myfile.crypt > myfile.txt Enter key: # ll myfile.txt -rw------- 1 root users 29 Dec 12 11:51 myfile.txt # cat myfile.txt This is test file for crypt.
crypt command checks input file and get to know its encrypted one. So it uses key supplied by user to decrypt it into output file specified in command. You get your file back as it was!