我想將用戶添加到運行我的節點應用程序的服務器。現在我使用:如何從節點內創建一個Ubuntu用戶
exec("useradd -mp {password-hash}")
與得到由
exec("mkpasswd -m des {password}")
這將使密碼在進程列表中可見創建一個哈希,而應該不惜一切代價避免。
這就是爲什麼我想知道在npm上是否有一個模塊或更容易的方式來以編程方式向系統添加linux用戶(這是必要的,因爲我正在構建的應用程序在用戶註冊時在系統上創建用戶帳戶在網上)。這可以不用像我現在正在做的那樣喚起系統命令呢?我沒有找到npm模塊,也沒有發現任何使用節點與ubuntu/unix用戶管理進行交互的信息。
解決方案
從頂部答案使用穆斯塔法的提示,我實現了一個版本使用spawn
的mkpasswd
命令。在CoffeeScript中,它應該是這樣的:
{spawn} = require 'child_process'
child = spawn 'mkpasswd', ['-m','des','--stdin']
child.stdout.on 'data', (data)->
console.log 'password hash arrived: ', data.toString()
child.stdin.write 'password'
確保你正確的錯誤處理的事件處理程序添加到child.stderr
和child.stdout
在調試代碼。
謝謝你的提示,特別是帶'spawn'的提示,我會嘗試實現那個。 因爲crypt(3)似乎實現了一個非標準的DES算法,所以我通過npm模塊生成散列失敗了。 – arvidkahl