Tuesday, 15 June 2010

how to read shadow file in linux using python script -



how to read shadow file in linux using python script -

file = open('/etc/shadow', 'r') print(file)

getting error file = open('/etc/shadow', 'r') ioerror: [errno 13] permission denied: '/etc/shadow'

on systems /etc/shadow owned root rw permissions.

$ ls -la /etc/shadow

-rw------- 1 root root 692 jun 10 19:24 /etc/shadow need either:

change permissons (don't not safe) running 'chmod o+r /etc/shadow' root. give 'other' users read rights

run programme root. either a. starting root su -c 'python mypython.py' //you asked provide root password.

b. starting sudo [1] sudo python mypython.py depends on sudo configuration best bet other starting python root.

also illustration phone call sudo within python[5].

c. set setuid bit on programme [2] not work python interpreted language , modern unix systems disallow (exception beingness perl) setuid on interpreted programs opposed compiled/binaries.

chown root programname # set owner root

chmod +s programname # gives programme right run root.

regardless of whom starts it.

[1]http://en.wikipedia.org/wiki/sudo

[2]http://en.wikipedia.org/wiki/setuid

[3]open file superuser in python

[4]setuid bit on python script : linux vs solaris

[5]using sudo python script

the problem not source code or python. not having right file scheme rights '/etc/shadow' file.

file-io

No comments:

Post a Comment