前言
本文主要介紹了Node.js命令行/批處理更改Linux用戶密碼的相關內容,分享出來供大家參考學習,下面話不多說了,來一起看看詳細的介紹吧
hpasswd 可在批處理文件中批量更改Linux用戶的密碼。
用法:
chpasswd [options]
option主要為一些密碼加密選項
-c, --crypt-method
Use the specified method to encrypt the passwords.
The available methods are DES, MD5, NONE, and SHA256 or SHA512 if your libc support these methods.
-e, --encrypted
Supplied passwords are in encrypted form.
-h, --help
Display help message and exit.
-m, --md5
Use MD5 encryption instead of DES when the supplied passwords are not encrypted.
-s, --sha-rounds
Use the specified number of rounds to encrypt the passwords.
The value 0 means that the system will choos
輸入命令后,按 username:password 格式輸入用戶名密碼,一行一個,如:
chpasswdnewghost:4567
用這種方法可在node.js中使用:
var cp = require('child_process')//更新密碼var chpasswd = cp.spawn('chpasswd')var errmsg//查看是否有錯誤chpasswd.stderr.on('data', function (data) { errmsg += data.toString()})chpasswd.on('exit', function(code) { if (cb) { errmsg ? cb(new Error(errmsg)) : cb() }})//寫入密碼chpasswd.stdin.write(username + ':' + password)chpasswd.stdin.end()總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對錯新站長站的支持。
新聞熱點
疑難解答
圖片精選