Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

import os
import getpass

getpass.getuser

getpass.getuser()
'dclong'

getpass.getpass

Prompt the user for a password without echoing. This is a secure way of asking user for password in a Python script.

getpass.getpass()

os.getuid

os.getuid()
1000

os.getgid

os.getgid()
1000

os.geteuid

os.geteuid()
1000

os.getegid

os.getegid()
1000

os.getresuid

os.getresuid()
(1000, 1000, 1000)

os.getresgid

os.getresgid()
(1000, 1000, 1000)

pwd

You can use the pwd module to get the user ID and group ID of any user.

import pwd
pwd.getpwnam("dclong")
pwd.struct_passwd(pw_name='dclong', pw_passwd='x', pw_uid=501, pw_gid=20, pw_gecos='dclong', pw_dir='/home/dclong', pw_shell='/bin/bash')
pwd.getpwnam("dclong").pw_gid
20
pwd.getpwuid(501)
pwd.struct_passwd(pw_name='dclong', pw_passwd='x', pw_uid=501, pw_gid=20, pw_gecos='dclong', pw_dir='/home/dclong', pw_shell='/bin/bash')
pwd.getpwuid(501).pw_gid
20

Test User’s Access to Path

os.access("/home", os.R_OK)
True
os.access("/home", os.W_OK)
False
!ls -lha /home
total 12K
drwxr-xr-x  1 root   root   4.0K Jun 28 18:12 .
drwxr-xr-x  1 root   root   4.0K Jun 28 18:12 ..
drwxr-x--- 12 dclong docker 4.0K Jul  5 17:25 dclong
os.access("/tmp", os.W_OK)
True