About nixCraft

Topics

Linux Password trick with immutable bit using chattr command

Posted by Vivek Gite [Last updated: November 26, 2007]

With the help of utility called chattr, you can changes the file attributes on a Linux second extended file system. The operator + causes the selected attributes to be added to the existing attributes of the files; - causes them to be removed; and = causes them to be the only attributes that the files have.

1) Login as the root user

2) Type the following command to write protect /etc/shadow file:
# chattr +i /etc/shadow

3) Now lets test it with user vivek. Login as user vivek and type passwd command to change password:

$ passwd

Changing password for user vivek.
Changing password for vivek
(current) UNIX password: OLDPASSWED
New password: NEWPASSWD
Retype new password:NEWPASSWD
passwd: all authentication tokens updated successfully.

4) Now logout and try to login with new password. What you can't? Use the old password you can login now.A file with the 'i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

5) Get the list of Linux second extended file system using the lsatter command (run as root user :-) )

# lsattr /etc/shadow

----i-------- /etc/shadow

6) For rest of Linux second extended file system attributes read man chatter, man lsatter.

7) Please note that even root user is not allowed to change password. Before doing this root need to remove the attribute using command:

# chattr -i /etc/shadow
# lsattr /etc/shadow

------------- /etc/shadow

E-mail this to a friend      Printable version

You may also be interested in other helpful articles:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.