See also
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 to True or False.
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 to True.
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'):
# ...
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')
Get the absolute path to the user’s home directory
Example:
import fabtools
home = fabtools.user.home_directory('alice')
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
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')
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',
])