Class Users
Index
Constructors
Accessors
Methods
Constructors
constructor
-
Parameters
- options: UsersOptions
Returns Users
Methods
add
addGroup
addPasskey
authorizeKey
-
Adds a key to the user's
authorized_keys(a directory of mode 0700, a file of 0600, both theirs). A key already there is not added twice.Parameters
- username: string
- key: JsonWebKey
- comment: string
Returns Promise<void>
byName
-
A user by name.
Parameters
- username: string
Returns User | undefined
changeUid
-
Gives an account another uid, and hands over the files in its home directory (
/etc/shadowis keyed by name, so it does not change).Parameters
- uid: number
- newUid: number
Returns Promise<void>
ensureGroup
ensureKeypair
-
The user's public key, making the pair first if there is none. The private half is encrypted under
password, which has to be the user's current one. A key that exists but cannot be unlocked with it (an administrator changed the password since) is not replaced: that would destroy it.Parameters
- uid: number
- password: string
Returns Promise<JsonWebKey>
findGroup
-
A group by name, or by gid when
specis a number.Parameters
- spec: string | number
Returns Group | undefined
freeId
-
The lowest unused id from
from, among the users' and the groups'.Parameters
- kind: "uid" | "gid"
- from: number
- to: number = Infinity
Returns number
get
-
Get a user by UID
Parameters
- uid: number
Returns User | undefined
getAuthorizedKeys
-
The keys the user may log in with (
~/.ssh/authorized_keys); none when the file is missingParameters
- username: string
Returns Promise<JsonWebKey[] | undefined>
getPasskeys
getPublicKey
-
The user's public key (
~/.ssh/id_ecdsa.pub), ornullwhen there is none yetParameters
- uid: number
Returns Promise<JsonWebKey | null>
hasPasskeys
isLocked
-
Whether the account is locked (
passwd -l)Parameters
- uid: number
Returns boolean
load
-
Load users from the filesystem
Returns Promise<void>
lock
-
Makes the account unusable for password logins: a
!before the hash (passwd -l)Parameters
- uid: number
Returns Promise<void>
login
-
login(
username: string,
password?: string,
passkeyCredential?: PublicKeyCredential,
): Promise<{ cred: Credentials; user: User }>Login a user
Parameters
- username: string
Optionalpassword: stringOptionalpasskeyCredential: PublicKeyCredential
Returns Promise<{ cred: Credentials; user: User }>
modifyGroup
password
-
Changes
uid's password (the first terminal's user, when none is given), after checking the old oneParameters
- oldPassword: string
- newPassword: string
- uid: number = ...
Returns Promise<void>
remove
removeGroup
-
Removes a group. A user's primary group cannot go while the user exists.
Parameters
- gid: number
Returns Promise<void>
removePasskey
rename
-
Gives the user a new name everywhere it is written: the account,
/etc/shadow, and the private group when it had one.Parameters
- uid: number
- name: string
Returns Promise<void>
resetPassword
-
An administrator sets a password without knowing the old one. The hash and
/etc/shadoware rewritten, and a lock is lifted. The private key in~/.sshstays encrypted under the old password, so it can no longer be unlocked, as with an encrypted home directory on Linux; nothing at login needs it.Parameters
- uid: number
- newPassword: string
Returns Promise<void>
savePasskeys
secureShadow
-
Mode
0640, owned by root and theshadowgroup (root's own group until that exists)Returns Promise<void>
sessionFor
-
A session for
usernamewithout a password, for a login that has already been proved some other way (a key). An expired account is closed to it as to any login; a locked password is not (that stops passwords, as on Linux). Fails with the same message as a wrong password so a name cannot be probed.Parameters
- username: string
Returns Promise<{ cred: Credentials; user: User }>
setAging
setMembership
-
Adds or removes a user from a group's members.
Parameters
- uid: number
- gid: number
- member: boolean
Returns Promise<void>
signWithKey
-
signWithKey(
uid: number,
password: string,
data: Uint8Array,
): Promise<{ publicKey: JsonWebKey; signature: Uint8Array }>Signs
datawith the user's key (making the pair first if there is none), for a login to another machine. The private key is decrypted here with the user's password and never leaves; the caller gets the public key and the signature.Parameters
- uid: number
- password: string
- data: Uint8Array
Returns Promise<{ publicKey: JsonWebKey; signature: Uint8Array }>
unlock
-
Takes the
!away (passwd -u); refused when that would leave no password at allParameters
- uid: number
Returns Promise<void>
unlockPrivateKey
-
The private key, decrypted with the user's password, or
null(no key, or a wrong password)Parameters
- uid: number
- password: string
Returns Promise<JsonWebKey | null>
Every group, by gid: the registry, plus the primary group of any user it does not yet name.