How can I lock files and programs with custom-set passwords?
That is, without changing the permissions of the file so that the sudo password has to be used...
How can I lock files and programs with custom-set passwords?
That is, without changing the permissions of the file so that the sudo password has to be used...
Possible method that is not exactly what you are asking
sudo su
cd ~
mkdir tmp
cd tmp
touch file.txt
chattr -i file.txt
exit
Back on the normal prompt nobody can do anything with the file.
You need to revert the "chattr" command with
chattr +i file.txt
to have normal access. "chattr" can also be used for other permissions. The +a
option will make it possible to append to a file but nothing else.
From the make page the options:
Select the new attributes for the files: append only (a), compressed (c), no dump (d), extent format (e), immutable (i), data journalling (j), secure deletion (s), no tail-merging (t), undeletable (u), no atime updates (A), synchronous directory updates (D), synchronous updates (S), and top of directory hierarchy (T).
For a custom-set password encryption, I would recommend the gpg symmetric cypher. Encoding:
user@computer$ gpg --output doc.gpg --symmetric doc
This will ask for a passphrase and create an encrypted version of doc.
Decoding:
user@computer$ gpg --output doc --decrypt doc.gpg
This will ask for a passphrase and decrypt doc.gpg as doc.
The question is not quite clear with the sudo password. When you run commands with sudo, you are asked your user password on ubuntu. The password of root user is another password, which you can set with the following command:
user@computer$ sudo passwd root
Linux file systems provide protection by permissions. However, in case somebody boots e.g. a live Ubuntu on your computer, or take your HDD, they can read all your files. Partition encryption is a good tool to prevent this type of data theft.
There are several tools you can use to obtain a finer grain of control over files.
First, and most important, each user must have her or her own account.
From there, your first line of defense is standard linux permissions. Make your home directory or a sub directory private.
chmod 700 /home/your_user
If you need finer grain of control, use acl . acl allow you to set permissions per user.
See https://help.ubuntu.com/community/FilePermissionsACLs
One of those two options is going to be sufficient for most user cases.
The limitation of permissions are that anyone with root or physical access will be able to access the files.
If you need more then that, or if you need to restrict root access, your next option is to use encryption.
You can encrypt your home directory either at the time or installation or later. See https://help.ubuntu.com/community/EncryptedHome
You can make a separate encrypted directory (see above link) and Is there a tool to encrypt a file or directory?
Take care with encryption, as long as the file is decrypted, and your user can read the file, so can root.