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 ~]#  
        

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值