Node.js命令行/批處理中如何更改Linux用戶密碼淺析
前言
本文主要介紹了Node.js命令行/批處理更改Linux用戶密碼的相關(guān)內(nèi)容,分享出來(lái)供大家參考學(xué)習(xí),下面話不多說(shuō)了,來(lái)一起看看詳細(xì)的介紹吧
hpasswd 可在批處理文件中批量更改Linux用戶的密碼。
用法:
chpasswd [options]
option主要為一些密碼加密選項(xiàng)
-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 格式輸入用戶名密碼,一行一個(gè),如:
chpasswd newghost:4567
用這種方法可在node.js中使用:
var cp = require('child_process')
//更新密碼
var chpasswd = cp.spawn('chpasswd')
var errmsg
//查看是否有錯(cuò)誤
chpasswd.stderr.on('data', function (data) {
errmsg += data.toString()
})
chpasswd.on('exit', function(code) {
if (cb) {
errmsg
? cb(new Error(errmsg))
: cb()
}
})
//寫(xiě)入密碼
chpasswd.stdin.write(username + ':' + password)
chpasswd.stdin.end()
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
Ubuntu中搭建Nodejs開(kāi)發(fā)環(huán)境過(guò)程分享
這篇文章主要介紹了Ubuntu中搭建Nodejs開(kāi)發(fā)環(huán)境過(guò)程,比較郁悶的是apt-get安裝失敗了,如果有遇到一樣問(wèn)題的朋友,可以參考一下本文2014-06-06
基于socket.io+express實(shí)現(xiàn)多房間聊天
本文給大家分享的是使用node.js,基于socket.io+express實(shí)現(xiàn)多房間聊天的代碼,非常的實(shí)用,有需要的小伙伴可以來(lái)參考下2016-03-03
node.js中的fs.renameSync方法使用說(shuō)明
這篇文章主要介紹了node.js中的fs.renameSync方法使用說(shuō)明,本文介紹了fs.renameSync的方法說(shuō)明、語(yǔ)法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下2014-12-12
Node.js中的http請(qǐng)求客戶端示例(request client)
本篇文章主要介紹了Node.js中的http請(qǐng)求客戶端示例(request client),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
手動(dòng)下載Chrome并解決puppeteer無(wú)法使用問(wèn)題
本篇文章主要介紹了手動(dòng)下載Chrome并解決puppeteer無(wú)法使用問(wèn)題,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11
Node.js的文件權(quán)限及讀寫(xiě)flag詳解
Node.js對(duì)文件的讀寫(xiě)還是相當(dāng)靈活的,因?yàn)樽约豪鲜怯洸蛔∥募蚰夸洐?quán)限的數(shù)值表達(dá)和字符表達(dá)。所以整理出這篇文章,方便以后查閱,下面來(lái)一起看看吧。2016-10-10
Node.js自動(dòng)生成API文檔的實(shí)現(xiàn)
本文主要介紹了Node.js自動(dòng)生成API文檔,包含基于swagger-jsdoc+swagger-ui-express快速實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03

