import pwd
import operator
# Load all of the user data, sorted by username
all_user_data = pwd.getpwall()
interesting_users = sorted((u
for u in all_user_data
if not u.pw_name.startswith('_')),
key=operator.attrgetter('pw_name'))
# Find the longest lengths for a few fields
username_length = max(len(u.pw_name) for u in interesting_users) + 1
home_length = max(len(u.pw_dir) for u in interesting_users) + 1
# Print report headers
fmt = '%-*s %4s %-*s %s'
print fmt % (username_length, 'User',
'UID',
home_length, 'Home Dir',
'Description')
print '-' * username_length, '----', '-' * home_length, '-' * 30
# Print the data
for u in interesting_users:
print fmt % (username_length, u.pw_name,
u.pw_uid,
home_length, u.pw_dir,
u.pw_gecos)
上面的程序从 linux 密码文件中获取密码, 我想创建一个程序来显示维护用户登录日志的 linux 内核文件。 如何进入内核请帮忙.......
最佳答案
看看 wtmp 和 utmp。有 API - 检查 man wtmp
关于python - 使用python获取密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3873128/