how to read shadow file in linux using python script
up vote
0
down vote
favorite
file = open('/etc/shadow', 'r')
print(file)
getting error like this
file = open('/etc/shadow', 'r')
IOError: [Errno 13] Permission denied: '/etc/shadow'
file-io
add a comment |
up vote
0
down vote
favorite
file = open('/etc/shadow', 'r')
print(file)
getting error like this
file = open('/etc/shadow', 'r')
IOError: [Errno 13] Permission denied: '/etc/shadow'
file-io
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
file = open('/etc/shadow', 'r')
print(file)
getting error like this
file = open('/etc/shadow', 'r')
IOError: [Errno 13] Permission denied: '/etc/shadow'
file-io
file = open('/etc/shadow', 'r')
print(file)
getting error like this
file = open('/etc/shadow', 'r')
IOError: [Errno 13] Permission denied: '/etc/shadow'
file-io
file-io
asked Jun 22 '14 at 8:02
Poke
1115
1115
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
On most systems /etc/shadow is owned by root with rw permissions.
$ ls -la /etc/shadow
-rw------- 1 root root 692 Jun 10 19:24 /etc/shadow
You need to either:
- Change the permissons (don't do this it is not safe)
but you could this by running 'chmod o+r /etc/shadow' as root. This will give the 'other' users read rights to Run your program as root. Either by
a. Starting it as rootsu -c 'python myPython.py'
//you will be asked to provide the root password.b. Starting it with sudo [1]
sudo python myPython.py
this all depends on you sudo configuration but is your best bet other then just starting python as root.
Also an example to call sudo from within python[5].
c. Set setuid bit on the program [2]
This will most likely not work as Python is an interpreted language and most modern Unix systems will disallow (exception being Perl) setuid on interpreted programs as opposed to compiled/binaries.
chown root programName # Set owner to be root
chmod +s programName # This gives the program itself the right to run as root.
Regardless of whom starts it.
[1]http://en.wikipedia.org/wiki/Sudo
[2]http://en.wikipedia.org/wiki/Setuid
[3]Open a file as superuser in python
[4]Setuid bit on python script : Linux vs Solaris
[5]Using sudo with Python script
The problem is not with the source code or python. But with not having the correct file system rights to the '/etc/shadow' file.
please post the code
– Poke
Jun 22 '14 at 8:13
thank u it's working...
– Poke
Jun 22 '14 at 11:37
add a comment |
up vote
0
down vote
In python 3 you can do:
import spwd
spwd.getspnam('username')
More information about the spwd
module can be found here: https://docs.python.org/3/library/spwd.html#module-spwd
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
On most systems /etc/shadow is owned by root with rw permissions.
$ ls -la /etc/shadow
-rw------- 1 root root 692 Jun 10 19:24 /etc/shadow
You need to either:
- Change the permissons (don't do this it is not safe)
but you could this by running 'chmod o+r /etc/shadow' as root. This will give the 'other' users read rights to Run your program as root. Either by
a. Starting it as rootsu -c 'python myPython.py'
//you will be asked to provide the root password.b. Starting it with sudo [1]
sudo python myPython.py
this all depends on you sudo configuration but is your best bet other then just starting python as root.
Also an example to call sudo from within python[5].
c. Set setuid bit on the program [2]
This will most likely not work as Python is an interpreted language and most modern Unix systems will disallow (exception being Perl) setuid on interpreted programs as opposed to compiled/binaries.
chown root programName # Set owner to be root
chmod +s programName # This gives the program itself the right to run as root.
Regardless of whom starts it.
[1]http://en.wikipedia.org/wiki/Sudo
[2]http://en.wikipedia.org/wiki/Setuid
[3]Open a file as superuser in python
[4]Setuid bit on python script : Linux vs Solaris
[5]Using sudo with Python script
The problem is not with the source code or python. But with not having the correct file system rights to the '/etc/shadow' file.
please post the code
– Poke
Jun 22 '14 at 8:13
thank u it's working...
– Poke
Jun 22 '14 at 11:37
add a comment |
up vote
1
down vote
On most systems /etc/shadow is owned by root with rw permissions.
$ ls -la /etc/shadow
-rw------- 1 root root 692 Jun 10 19:24 /etc/shadow
You need to either:
- Change the permissons (don't do this it is not safe)
but you could this by running 'chmod o+r /etc/shadow' as root. This will give the 'other' users read rights to Run your program as root. Either by
a. Starting it as rootsu -c 'python myPython.py'
//you will be asked to provide the root password.b. Starting it with sudo [1]
sudo python myPython.py
this all depends on you sudo configuration but is your best bet other then just starting python as root.
Also an example to call sudo from within python[5].
c. Set setuid bit on the program [2]
This will most likely not work as Python is an interpreted language and most modern Unix systems will disallow (exception being Perl) setuid on interpreted programs as opposed to compiled/binaries.
chown root programName # Set owner to be root
chmod +s programName # This gives the program itself the right to run as root.
Regardless of whom starts it.
[1]http://en.wikipedia.org/wiki/Sudo
[2]http://en.wikipedia.org/wiki/Setuid
[3]Open a file as superuser in python
[4]Setuid bit on python script : Linux vs Solaris
[5]Using sudo with Python script
The problem is not with the source code or python. But with not having the correct file system rights to the '/etc/shadow' file.
please post the code
– Poke
Jun 22 '14 at 8:13
thank u it's working...
– Poke
Jun 22 '14 at 11:37
add a comment |
up vote
1
down vote
up vote
1
down vote
On most systems /etc/shadow is owned by root with rw permissions.
$ ls -la /etc/shadow
-rw------- 1 root root 692 Jun 10 19:24 /etc/shadow
You need to either:
- Change the permissons (don't do this it is not safe)
but you could this by running 'chmod o+r /etc/shadow' as root. This will give the 'other' users read rights to Run your program as root. Either by
a. Starting it as rootsu -c 'python myPython.py'
//you will be asked to provide the root password.b. Starting it with sudo [1]
sudo python myPython.py
this all depends on you sudo configuration but is your best bet other then just starting python as root.
Also an example to call sudo from within python[5].
c. Set setuid bit on the program [2]
This will most likely not work as Python is an interpreted language and most modern Unix systems will disallow (exception being Perl) setuid on interpreted programs as opposed to compiled/binaries.
chown root programName # Set owner to be root
chmod +s programName # This gives the program itself the right to run as root.
Regardless of whom starts it.
[1]http://en.wikipedia.org/wiki/Sudo
[2]http://en.wikipedia.org/wiki/Setuid
[3]Open a file as superuser in python
[4]Setuid bit on python script : Linux vs Solaris
[5]Using sudo with Python script
The problem is not with the source code or python. But with not having the correct file system rights to the '/etc/shadow' file.
On most systems /etc/shadow is owned by root with rw permissions.
$ ls -la /etc/shadow
-rw------- 1 root root 692 Jun 10 19:24 /etc/shadow
You need to either:
- Change the permissons (don't do this it is not safe)
but you could this by running 'chmod o+r /etc/shadow' as root. This will give the 'other' users read rights to Run your program as root. Either by
a. Starting it as rootsu -c 'python myPython.py'
//you will be asked to provide the root password.b. Starting it with sudo [1]
sudo python myPython.py
this all depends on you sudo configuration but is your best bet other then just starting python as root.
Also an example to call sudo from within python[5].
c. Set setuid bit on the program [2]
This will most likely not work as Python is an interpreted language and most modern Unix systems will disallow (exception being Perl) setuid on interpreted programs as opposed to compiled/binaries.
chown root programName # Set owner to be root
chmod +s programName # This gives the program itself the right to run as root.
Regardless of whom starts it.
[1]http://en.wikipedia.org/wiki/Sudo
[2]http://en.wikipedia.org/wiki/Setuid
[3]Open a file as superuser in python
[4]Setuid bit on python script : Linux vs Solaris
[5]Using sudo with Python script
The problem is not with the source code or python. But with not having the correct file system rights to the '/etc/shadow' file.
edited May 23 '17 at 12:27
Community♦
11
11
answered Jun 22 '14 at 8:07
Albert-Jan Stevens
1062
1062
please post the code
– Poke
Jun 22 '14 at 8:13
thank u it's working...
– Poke
Jun 22 '14 at 11:37
add a comment |
please post the code
– Poke
Jun 22 '14 at 8:13
thank u it's working...
– Poke
Jun 22 '14 at 11:37
please post the code
– Poke
Jun 22 '14 at 8:13
please post the code
– Poke
Jun 22 '14 at 8:13
thank u it's working...
– Poke
Jun 22 '14 at 11:37
thank u it's working...
– Poke
Jun 22 '14 at 11:37
add a comment |
up vote
0
down vote
In python 3 you can do:
import spwd
spwd.getspnam('username')
More information about the spwd
module can be found here: https://docs.python.org/3/library/spwd.html#module-spwd
add a comment |
up vote
0
down vote
In python 3 you can do:
import spwd
spwd.getspnam('username')
More information about the spwd
module can be found here: https://docs.python.org/3/library/spwd.html#module-spwd
add a comment |
up vote
0
down vote
up vote
0
down vote
In python 3 you can do:
import spwd
spwd.getspnam('username')
More information about the spwd
module can be found here: https://docs.python.org/3/library/spwd.html#module-spwd
In python 3 you can do:
import spwd
spwd.getspnam('username')
More information about the spwd
module can be found here: https://docs.python.org/3/library/spwd.html#module-spwd
edited Nov 9 at 20:46
Bill DeRose
5111521
5111521
answered Nov 9 at 18:20
Andreas
13
13
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24349293%2fhow-to-read-shadow-file-in-linux-using-python-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown