{"id":22484924,"url":"https://github.com/wmantly/linux-user","last_synced_at":"2025-08-02T18:30:55.482Z","repository":{"id":29393794,"uuid":"121439076","full_name":"wmantly/linux-user","owner":"wmantly","description":"Node module for Linux user and group control.","archived":false,"fork":true,"pushed_at":"2024-06-16T11:16:19.000Z","size":275,"stargazers_count":13,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-22T00:47:35.879Z","etag":null,"topics":["linux","nodejs","nodejs-modules","pam"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"wxygeek/linux-user","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wmantly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-13T21:31:57.000Z","updated_at":"2024-03-11T11:34:52.000Z","dependencies_parsed_at":"2023-01-16T22:30:37.717Z","dependency_job_id":null,"html_url":"https://github.com/wmantly/linux-user","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/wmantly/linux-user","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmantly%2Flinux-user","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmantly%2Flinux-user/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmantly%2Flinux-user/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmantly%2Flinux-user/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wmantly","download_url":"https://codeload.github.com/wmantly/linux-user/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmantly%2Flinux-user/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267790709,"owners_count":24144889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linux","nodejs","nodejs-modules","pam"],"created_at":"2024-12-06T17:11:45.485Z","updated_at":"2025-08-02T18:30:55.229Z","avatar_url":"https://github.com/wmantly.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# linux-user\n\n\nNode module for Linux user and group control.\n\nUse Node to manage Linux user easily. All APIs do what you think. Promise and \n`async\\await` out of the box. ES5 support! **Zero dependences!**\n\n**The module must be running on Linux and as root user !**\n\n[![NPM](https://nodei.co/npm/linux-sys-user.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/linux-sys-user/)\n\n## Notes\n\nThis is a fork of [wxygeek](https://github.com/wxygeek) abandoned [linux-user](https://github.com/wxygeek/linux-user) project.\n\n## Installation\n\n`$ npm install linux-sys-user --save`\n\nMost of the functions require privileged(root) access. The methods that\nsimply return information will work, as well as the methods that only work on\ncurrent user will also work with out root. \n\n\n## Testing\n\n`$ npm test`\n\nThe testing libraries only work with NodeJS 6 and up.\n\nUPDATE!\n\nNewer version of NPM does not allows executing as root, if you run into this\nissue, call mocha directly:\n\n```bash\n./node_modules/mocha/bin/mocha \n```\n\n## Usage\n\nThis works with your normal require and execute callback functions. Every method\ntakes a callback and is non-blocking.\n\n### Examples\n\n* add Linux user\n\n```js\nvar linuxUser = require('linux-sys-user');\n\nlinuxUser.addUser({username:\"gkuchan\", create_home:true, shell:null}, function (err, user) {\n  if(err) {\n    return console.error(err);\n  }\n  console.log(user);\n  // ------------------------------------------\n  // { username: 'gkuchan',\n  //   password: 'x',\n  //   uid: 1001,\n  //   gid: 1001,\n  //   fullname: '',\n  //   homedir: '/home/gkuchan',\n  //   shell: '/usr/sbin/nologin' }\n  // ------------------------------------------\n});\n```\n* get users\n\n```js\nvar linuxUser = require('linux-sys-user');\n\nlinuxUser.getUsers(function (err, users) {\n  if(err) {\n    return console.error(err);\n  }\n  console.log(users);\n  // ------------------------------------------\n  // [ { username: 'root',\n  //   password: 'x',\n  //   uid: 0,\n  //   gid: 0,\n  //   fullname: 'root',\n  //   homedir: '/root',\n  //   shell: '/bin/bash' },\n  // { username: 'daemon',\n  //   password: 'x',\n  //   uid: 1,\n  //   gid: 1,\n  //   fullname: 'daemon',\n  //   homedir: '/usr/sbin',\n  //   shell: '/usr/sbin/nologin' },\n  // { username: 'bin',\n  //   password: 'x',\n  //   uid: 2,\n  //   gid: 2,\n  //   fullname: 'bin',\n  //   homedir: '/bin',\n  //   shell: '/usr/sbin/nologin' } ]\n  //   ------------------------------------------\n  });\n```\n\n### Promises\n\nThis project works with promises right out of the box! Just grab the promise\nfunction.\n\n```js\nvar linuxUser = require('linux-sys-user').promise();\n```\n\nThis will NodeJS's `util.promisify` by default. You can pass your own promisify\nfunction like, like bluebird:\n\n```js\nvar bluebird = require('bluebird');\nvar linuxUser = require('linux-sys-user').promise(bluebird.promisify);\n\n```\n\n** `bluebird` is NOT included with this package! ** If you are using a older\nversion of NodeJS( less then 8 ) you will need something like it.\n\nThis will work with `.then()`, `.catch()` and the `async`/`await` pattern.\n\n```js\n\nlet user = await addUser({username:\"gkuchan\", create_home:true, shell:null});\nconsole.log(user);\n  // ------------------------------------------\n  // { username: 'gkuchan',\n  //   password: 'x',\n  //   uid: 1001,\n  //   gid: 1001,\n  //   fullname: '',\n  //   homedir: '/home/gkuchan',\n  //   shell: '/usr/sbin/nologin' }\n  // ------------------------------------------\n\n``` \n\n### Core APIs\n\n* linuxUser.addUser(config, callback)\n\n  This method is a front end to the `useradd` command on your system. Please\n  consult you systems man page for details on your version and implementation.\n\n\t* config Object\n    \n      * `username` *String* User name of the user to be created.\n      \n      * `shell` *String* or *Null* Path to the login shell, setting `null` will\n      use `/usr/sbin/nologin` as the path.\n\n      ```\n      The name of the user's login shell. The default is to leave this\n      field blank, which causes the system to select the default login\n      shell specified by the SHELL variable in /etc/default/useradd, or\n      an empty string by default.\n      ```\n\n      * `create_home` *Boolean* `true` will create the home directory, `false`\n      will not.\n\n      * `home_dir` *String* Path to the user home directory.\n\n        ```\n        The new user will be created using HOME_DIR as the value for the\n        user's login directory. The default is to append the LOGIN name to\n        BASE_DIR and use that as the login directory name. The directory\n        HOME_DIR does not have to exist but will not be created if it is\n        missing.\n        ```\n\n      * `expiredate` *String* The date on which the user account will be\n      disabled. The date is specified in the format `YYYY-MM-DD`..\n\n      ```\n      If not specified, useradd will use the default expiry date\n      specified by the EXPIRE variable in /etc/default/useradd, or an\n      empty string (no expiry) by default.\n      ```\n\n      * `skel` *String*\n\n      ```\n      The skeleton directory, which contains files and directories to be\n      copied in the user's home directory, when the home directory is\n      created by useradd.\n\n      This option is only valid if the -m (or --create-home) option is\n      specified.\n\n      If this option is not set, the skeleton directory is defined by the\n      SKEL variable in /etc/default/useradd or, by default, /etc/skel.\n\n      If possible, the ACLs and extended attributes are copied.\n\n      ```\n      * `system` *Boolean* Create a system account.\n\n      ```\n      System users will be created with no aging information in\n      /etc/shadow, and their numeric identifiers are chosen in the\n      SYS_UID_MIN-SYS_UID_MAX range, defined in /etc/login.defs, instead\n      of UID_MIN-UID_MAX (and their GID counterparts for the creation of\n      groups).\n\n      Note that useradd will not create a home directory for such a user,\n      regardless of the default setting in /etc/login.defs (CREATE_HOME).\n      You have to specify the -m options if you want a home directory for\n      a system account to be created.\n\n      ```\n      * `selinux_user` *String* The SELinux user for the user's login.\n\n      ```\n      The default is to leave this field blank, which causes the system to\n      select the default SELinux user.\n      ```\n\n\t* callback function(err, userInfo)\n\n* linuxUser.getExpiration(username, callback)\n\n  Gets expiration information about a user, returns an Object:\n  ```js\n  Expiration data {\n    changed: 2023-04-04T04:00:00.000Z,\n    passwordExpires: null,\n    inactive: null,\n    accountExpires: 1970-01-31T05:00:00.000Z,\n    minDays: 0,\n    maxDays: 99999,\n    warnDays: 7\n  }\n  ```\n\n* linuxUser.setExpiration(config, callback)\n  \n  Set the user password expiration and inactivity.\n  * config object\n\n  * `lastday` LAST_DAY\n    Set the number of days since January 1st, 1970 when the password was last\n    changed. The date may also be expressed in the format YYYY-MM-DD (or the\n    format more commonly used in your area).\n    **Setting this to zero will force the password to be changed on the next\n    login**\n\n  * `expiredate` EXPIRE_DATE\n    Set the date or number of days since January 1, 1970 on which the\n    user's account will no longer be accessible. The date may also be expressed\n    in the format YYYY-MM-DD (or the format more commonly used in your area). A\n    user whose account is locked must contact the system administrator before\n    being able to use the system again. Passing the number -1 as the EXPIRE_DATE\n    will remove an account expiration date.\n\n  * `inactive` INACTIVE\n    Set the number of days of inactivity after a password has expired before the\n    account is locked. The INACTIVE option is the number of days of inactivity.\n    A user whose account is locked must contact the system administrator before\n    being able to use the system again. Passing the number -1 as the INACTIVE\n    will remove an account's inactivity.\n\n    **`lastday`, `expiredate`, and `inactive` can be set as a String of days\n    since January 1st, 1970, or formatted YYYY-MM-DD or a native Date object.**\n\n\n  * `minDays` MIN_DAYS\n    Set the minimum number of days between password changes to MIN_DAYS. A value\n    of zero for this field indicates that the user may change his/her password\n    at any time.\n\n  * `maxDays` MAX_DAYS\n    Set the maximum number of days during which a password is valid. When\n    MAX_DAYS plus LAST_DAY is less than the current day, the user will be\n    required to change his/her password before being able to use his/her\n    account. This occurrence can be planned for in advance by use of the\n    `warnDays` option, which provides the user with advance warning. Passing the\n    number -1 as MAX_DAYS will remove checking a password's validity.\n\n  * `warnDays` WARN_DAYS\n    Set the number of days of warning before a password change is required. The\n    WARN_DAYS option is the number of days prior to the password expiring that a\n    user will be warned his/her password is about to expire.\n\n* linuxUser.removeUser(username, callback)\n\t* username String\n\t* callback function(err)\n\t\n* linuxUser.getUsers(callback)\n\t* callback function(err, usersInfo)\n\t\n* linuxUser.getUserInfo(username, callback)\n\t* username String\n\t* callback function(err, userInfo)\n\t\n* linuxUser.getUserGroups(username, callback)\n\t* username String\n\t* callback function(err, groups)\n\t\n* linuxUser.setPassword(username, password, callback)\n\t* username String\n\t* password String\n\t* callback function(err)\n\t\n* linuxUser.addGroup(groupname, callback)\n\t* groupname String\n\t* callback function(err, groupInfo)\n\t\n* linuxUser.removeGroup(groupname, callback)\n\t* groupname String\n\t* callback function(err)\n\t\n* linuxUser.getGroups(callback)\n\t* callback function(err, groupsInfo)\n\t\n* linuxUser.getGroupInfo(groupname, callback)\n\t* groupname String\n\t* callback function(err, groupInfo)\n\t\n* linuxUser.addUserToGroup(username, groupname, callback)\n\t* username String\n\t* groupname String\n\t* callback function(err)\n\n### Other APIs\n\n* linuxUser.validateUsername(username)\n\t* return boolen\n\t* check a string is a valid linux username or not\n\n\n* linuxUser.verifySSHKey(key, callback)\n\t* key String\n\t* callback function(err, key info)\n\n\n* linuxUser.addSSHtoUser(user, key, callback)\n\t* user String\n\t* key String\n\t* callback function(err, true)\n\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwmantly%2Flinux-user","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwmantly%2Flinux-user","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwmantly%2Flinux-user/lists"}