Gathering detailed insights and metrics for linux-sys-user
Gathering detailed insights and metrics for linux-sys-user
Gathering detailed insights and metrics for linux-sys-user
Gathering detailed insights and metrics for linux-sys-user
npm install linux-sys-user
Typescript
Module System
Node Version
NPM Version
JavaScript (97.45%)
Makefile (2.55%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
13 Stars
109 Commits
6 Forks
1 Watchers
2 Branches
1 Contributors
Updated on Mar 11, 2024
Latest Version
1.2.0
Package Id
linux-sys-user@1.2.0
Unpacked Size
44.02 kB
Size
12.38 kB
File Count
12
NPM Version
10.2.3
Node Version
20.10.0
Published on
Jan 09, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Node module for Linux user and group control.
Use Node to manage Linux user easily. All APIs do what you think. Promise and
async\await
out of the box. ES5 support! Zero dependences!
The module must be running on Linux and as root user !
This is a fork of wxygeek abandoned linux-user project.
$ npm install linux-sys-user --save
Most of the functions require privileged(root) access. The methods that simply return information will work, as well as the methods that only work on current user will also work with out root.
$ npm test
The testing libraries only work with NodeJS 6 and up.
UPDATE!
Newer version of NPM does not allows executing as root, if you run into this issue, call mocha directly:
1./node_modules/mocha/bin/mocha
This works with your normal require and execute callback functions. Every method takes a callback and is non-blocking.
1var linuxUser = require('linux-sys-user'); 2 3linuxUser.addUser({username:"gkuchan", create_home:true, shell:null}, function (err, user) { 4 if(err) { 5 return console.error(err); 6 } 7 console.log(user); 8 // ------------------------------------------ 9 // { username: 'gkuchan', 10 // password: 'x', 11 // uid: 1001, 12 // gid: 1001, 13 // fullname: '', 14 // homedir: '/home/gkuchan', 15 // shell: '/usr/sbin/nologin' } 16 // ------------------------------------------ 17});
1var linuxUser = require('linux-sys-user'); 2 3linuxUser.getUsers(function (err, users) { 4 if(err) { 5 return console.error(err); 6 } 7 console.log(users); 8 // ------------------------------------------ 9 // [ { username: 'root', 10 // password: 'x', 11 // uid: 0, 12 // gid: 0, 13 // fullname: 'root', 14 // homedir: '/root', 15 // shell: '/bin/bash' }, 16 // { username: 'daemon', 17 // password: 'x', 18 // uid: 1, 19 // gid: 1, 20 // fullname: 'daemon', 21 // homedir: '/usr/sbin', 22 // shell: '/usr/sbin/nologin' }, 23 // { username: 'bin', 24 // password: 'x', 25 // uid: 2, 26 // gid: 2, 27 // fullname: 'bin', 28 // homedir: '/bin', 29 // shell: '/usr/sbin/nologin' } ] 30 // ------------------------------------------ 31 });
This project works with promises right out of the box! Just grab the promise function.
1var linuxUser = require('linux-sys-user').promise();
This will NodeJS's util.promisify
by default. You can pass your own promisify
function like, like bluebird:
1var bluebird = require('bluebird'); 2var linuxUser = require('linux-sys-user').promise(bluebird.promisify); 3
** bluebird
is NOT included with this package! ** If you are using a older
version of NodeJS( less then 8 ) you will need something like it.
This will work with .then()
, .catch()
and the async
/await
pattern.
1 2let user = await addUser({username:"gkuchan", create_home:true, shell:null}); 3console.log(user); 4 // ------------------------------------------ 5 // { username: 'gkuchan', 6 // password: 'x', 7 // uid: 1001, 8 // gid: 1001, 9 // fullname: '', 10 // homedir: '/home/gkuchan', 11 // shell: '/usr/sbin/nologin' } 12 // ------------------------------------------ 13
linuxUser.addUser(config, callback)
This method is a front end to the useradd
command on your system. Please
consult you systems man page for details on your version and implementation.
config Object
username
String User name of the user to be created.
shell
String or Null Path to the login shell, setting null
will
use /usr/sbin/nologin
as the path.
The name of the user's login shell. The default is to leave this
field blank, which causes the system to select the default login
shell specified by the SHELL variable in /etc/default/useradd, or
an empty string by default.
create_home
Boolean true
will create the home directory, false
will not.
home_dir
String Path to the user home directory.
The new user will be created using HOME_DIR as the value for the
user's login directory. The default is to append the LOGIN name to
BASE_DIR and use that as the login directory name. The directory
HOME_DIR does not have to exist but will not be created if it is
missing.
expiredate
String The date on which the user account will be
disabled. The date is specified in the format YYYY-MM-DD
..
If not specified, useradd will use the default expiry date
specified by the EXPIRE variable in /etc/default/useradd, or an
empty string (no expiry) by default.
skel
StringThe skeleton directory, which contains files and directories to be
copied in the user's home directory, when the home directory is
created by useradd.
This option is only valid if the -m (or --create-home) option is
specified.
If this option is not set, the skeleton directory is defined by the
SKEL variable in /etc/default/useradd or, by default, /etc/skel.
If possible, the ACLs and extended attributes are copied.
system
Boolean Create a system account.System users will be created with no aging information in
/etc/shadow, and their numeric identifiers are chosen in the
SYS_UID_MIN-SYS_UID_MAX range, defined in /etc/login.defs, instead
of UID_MIN-UID_MAX (and their GID counterparts for the creation of
groups).
Note that useradd will not create a home directory for such a user,
regardless of the default setting in /etc/login.defs (CREATE_HOME).
You have to specify the -m options if you want a home directory for
a system account to be created.
selinux_user
String The SELinux user for the user's login.The default is to leave this field blank, which causes the system to
select the default SELinux user.
callback function(err, userInfo)
linuxUser.getExpiration(username, callback)
Gets expiration information about a user, returns an Object:
1Expiration data { 2 changed: 2023-04-04T04:00:00.000Z, 3 passwordExpires: null, 4 inactive: null, 5 accountExpires: 1970-01-31T05:00:00.000Z, 6 minDays: 0, 7 maxDays: 99999, 8 warnDays: 7 9}
linuxUser.setExpiration(config, callback)
Set the user password expiration and inactivity.
config object
lastday
LAST_DAY
Set the number of days since January 1st, 1970 when the password was last
changed. The date may also be expressed in the format YYYY-MM-DD (or the
format more commonly used in your area).
Setting this to zero will force the password to be changed on the next
login
expiredate
EXPIRE_DATE
Set the date or number of days since January 1, 1970 on which the
user's account will no longer be accessible. The date may also be expressed
in the format YYYY-MM-DD (or the format more commonly used in your area). A
user whose account is locked must contact the system administrator before
being able to use the system again. Passing the number -1 as the EXPIRE_DATE
will remove an account expiration date.
inactive
INACTIVE
Set the number of days of inactivity after a password has expired before the
account is locked. The INACTIVE option is the number of days of inactivity.
A user whose account is locked must contact the system administrator before
being able to use the system again. Passing the number -1 as the INACTIVE
will remove an account's inactivity.
lastday
, expiredate
, and inactive
can be set as a String of days
since January 1st, 1970, or formatted YYYY-MM-DD or a native Date object.
minDays
MIN_DAYS
Set the minimum number of days between password changes to MIN_DAYS. A value
of zero for this field indicates that the user may change his/her password
at any time.
maxDays
MAX_DAYS
Set the maximum number of days during which a password is valid. When
MAX_DAYS plus LAST_DAY is less than the current day, the user will be
required to change his/her password before being able to use his/her
account. This occurrence can be planned for in advance by use of the
warnDays
option, which provides the user with advance warning. Passing the
number -1 as MAX_DAYS will remove checking a password's validity.
warnDays
WARN_DAYS
Set the number of days of warning before a password change is required. The
WARN_DAYS option is the number of days prior to the password expiring that a
user will be warned his/her password is about to expire.
linuxUser.removeUser(username, callback)
linuxUser.getUsers(callback)
linuxUser.getUserInfo(username, callback)
linuxUser.getUserGroups(username, callback)
linuxUser.setPassword(username, password, callback)
linuxUser.addGroup(groupname, callback)
linuxUser.removeGroup(groupname, callback)
linuxUser.getGroups(callback)
linuxUser.getGroupInfo(groupname, callback)
linuxUser.addUserToGroup(username, groupname, callback)
linuxUser.validateUsername(username)
linuxUser.verifySSHKey(key, callback)
linuxUser.addSSHtoUser(user, key, callback)
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
6 existing vulnerabilities detected
Details
Reason
Found 2/13 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More