fabtools.user
¶
Users¶
See also
-
fabtools.user.
create
(name, comment=None, home=None, create_home=None, skeleton_dir=None, group=None, create_group=True, extra_groups=None, password=None, system=False, shell=None, uid=None, ssh_public_keys=None, non_unique=False)[source]¶ Create a new user and its home directory.
If create_home is
None
(the default), a home directory will be created for normal users, but not for system users. You can override the default behaviour by setting create_home toTrue
orFalse
.If system is
True
, the user will be a system account. Its UID will be chosen in a specific range, and it will not have a home directory, unless you explicitely set create_home toTrue
.If shell is
None
, the user’s login shell will be the system’s default login shell (usually/bin/sh
).ssh_public_keys can be a (local) filename or a list of (local) filenames of public keys that should be added to the user’s SSH authorized keys (see
fabtools.user.add_ssh_public_keys()
).Example:
import fabtools if not fabtools.user.exists('alice'): fabtools.user.create('alice') with cd('/home/alice'): # ...
-
fabtools.user.
modify
(name, comment=None, home=None, move_current_home=False, group=None, extra_groups=None, login_name=None, password=None, shell=None, uid=None, ssh_public_keys=None, non_unique=False)[source]¶ Modify an existing user.
ssh_public_keys can be a (local) filename or a list of (local) filenames of public keys that should be added to the user’s SSH authorized keys (see
fabtools.user.add_ssh_public_keys()
).Example:
import fabtools if fabtools.user.exists('alice'): fabtools.user.modify('alice', shell='/bin/sh')
-
fabtools.user.
home_directory
(name)[source]¶ Get the absolute path to the user’s home directory
Example:
import fabtools home = fabtools.user.home_directory('alice')
-
fabtools.user.
local_home_directory
(name='')[source]¶ Get the absolute path to the local user’s home directory
Example:
import fabtools local_home = fabtools.user.local_home_directory()
Get the list of authorized SSH public keys for the user
-
fabtools.user.
add_ssh_public_key
(name, filename)[source]¶ Add a public key to the user’s authorized SSH keys.
filename must be the local filename of a public key that should be added to the user’s SSH authorized keys.
Example:
import fabtools fabtools.user.add_ssh_public_key('alice', '~/.ssh/id_rsa.pub')
-
fabtools.user.
add_ssh_public_keys
(name, filenames)[source]¶ Add multiple public keys to the user’s authorized SSH keys.
filenames must be a list of local filenames of public keys that should be added to the user’s SSH authorized keys.
Example:
import fabtools fabtools.user.add_ssh_public_keys('alice', [ '~/.ssh/id1_rsa.pub', '~/.ssh/id2_rsa.pub', ])