How To

How to password protect user or file in Linux


Linux and its distributions are much secure and reliable operating systems than any commercial OS. Security is the key element of Linux that has attract so many users over all these years despite of its complex and often command based interface. In this article, I’m going to explain how you can protect your user password or files in Linux.

To password protect your files in Ubuntu or Linux, you don’t need any third software. Just right click on the file/folder you want to protect.
Select compress > Compression format > Other options > Enter any password
Check on ‘Encrypt’ > Create. That’s it. You have now compressed and password protected file or folder. If you want to ensure that no one can delete or move your file, open the terminal, cd to file location and use the following command :

  1. sudo chatter +i filename.ext

To undo this

  1. use sudo chattr –i filename.ext

Chattr is a command line utility that set/unset characteristics of file to save from accidental deletion or modification. + will add the attribute, – will remove and =: will append the attribute to existing attributes of the file.

To protect root or any user, you must have a strong password attached to it. In Linux world, passwords are managed directly from the command line. The passwd utility gives an easy access to all password related commands on your system. To change your password, type passwd command with nothing else. Shell will ask you to enter current password followed by your new one. With root or sudo privileges, you can also change anyone’s password on the system, if you know the password.

If you want to stop a user from access to system, you can lock its password using -1 flag. Simply use sudo passwd -1 username. To unlock use -u flag.

  1. sudo passwd –u username

You can also lock root by leaving only the sudo. Use

  1. sudo passwd -1 root

and it will lock all access to the root account.

One comment
  1. Sheila Rehman

    I didn’t know it would be so easy to protect files on Linux OS. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *