Busybox shell腳本修改密碼


/******************************************************************************
 *                        Busybox shell腳本修改密碼
 * 說明:
 *     需要在在Busybox文件系統中修改密碼,但是passwd命令需要交互才能修改密碼,
 * 原來Busybox提供了chpasswd命令,在shell中直接用passwd也是可行的。
 *
 *                                         2017-3-9 深圳 南山平山村 曾劍鋒
 *****************************************************************************/

一、參考文檔:
    1. how to change password with shell script in busybox 1.4.2
        http://www.avrfreaks.net/forum/how-change-password-shell-script-busybox-142    
    2. How do you change a user password in a script with busybox and openssl?
        http://stackoverflow.com/questions/2059069/how-do-you-change-a-user-password-in-a-script-with-busybox-and-openssl
    3. How to set a new password from bash?
        http://unix.stackexchange.com/questions/26738/how-to-set-a-new-password-from-bash

二、passwd幫助:
    [zengjf@root ~]#  passwd -h
    passwd: invalid option -- 'h'
    BusyBox v1.25.0 (2016-09-21 23:53:28 CST) multi-call binary.

    Usage: passwd [OPTIONS] [USER]

    Change USER's password (default: current user)

            -a ALG  Encryption method
            -d      Set password to ''
            -l      Lock (disable) account
            -u      Unlock (enable) account
    [zengjf@root ~]#  

三、解決辦法:
    1. 方法1: compile your own busybox configuration with chpasswd command。
    2. 方法2: 
        1. 編寫一個腳本如下:
            #!/bin/sh 
            passwd << EOF 
            <new password> 
            <new password> 
            EOF 
        2. 輸出效果如下
            [zengjf@root ~]#  ./chpasswd 
            Changing password for root
            New password: 
            Bad password: too weak
            Retype password: 
            passwd: password for root changed by root
            [zengjf@root ~]#  
        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM