linux mkpasswd - 密码生成器

【基本介绍】
作为linux admin要经常创建用户,并初始化密码。mkpasswd会生成一定强度的密码。

【安装】
yum instll expect

【基本参数】
[code="linux"]
# man mkpasswd
MKPASSWD(1) MKPASSWD(1)

NAME
mkpasswd - generate new password, optionally apply it to a user

SYNOPSIS
mkpasswd [ args ] [ user ]

INTRODUCTION
mkpasswd generates passwords and can apply them automatically to users. mkpasswd is based on the code from Chapter 23 of the O’Reilly
book "Exploring Expect".

USAGE
With no arguments, mkpasswd returns a new password.

mkpasswd

With a user name, mkpasswd assigns a new password to the user.

mkpasswd don

The passwords are randomly generated according to the flags below.

FLAGS
The -l flag defines the length of the password. The default is 9. The following example creates a 20 character password.

mkpasswd -l 20

The -d flag defines the minimum number of digits that must be in the password. The default is 2. The following example creates a
password with at least 3 digits.

mkpasswd -d 3

The -c flag defines the minimum number of lowercase alphabetic characters that must be in the password. The default is 2.

The -C flag defines the minimum number of uppercase alphabetic characters that must be in the password. The default is 2.

The -s flag defines the minimum number of special characters that must be in the password. The default is 1.

The -p flag names a program to set the password. By default, /etc/yppasswd is used if present, otherwise /bin/passwd is used.

The -2 flag causes characters to be chosen so that they alternate between right and left hands (qwerty-style), making it harder for
anyone watching passwords being entered. This can also make it easier for a password-guessing program.

The -v flag causes the password-setting interaction to be visible. By default, it is suppressed.

EXAMPLE
The following example creates a 15-character password that contains at least 3 digits and 5 uppercase characters.

mkpasswd -l 15 -d 3 -C 5
[/code]

【简单例子】
生成长度为10的密码
[code="linux"]
# mkpasswd -l 10
a9QVojdk8/
[/code]
生成长度为10,5个大写字母的密码
[code="linux"]
# mkpasswd -l 10 -C 5
2hzJB%Q8EG
[/code]
生成长度为15,特殊字符为5个,大写字符为5个的密码
[code="linux"]
# mkpasswd -l 15 -s 5 -C 5
H'rdi61K~L[]WH.
[/code]

【linux下随机生成密码方式】
#1
date +%s | sha256sum | base64 | head -c 32 ; echo
上述命令使用SHA来哈希日期,输出头32个字节。

#2
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
上述命令使用内嵌的/dev/urandom,只输出字符,结果取头32个。

#3
openssl rand -base64 32
上述命令使用系统自带的openssl的随机特点来产生随机密码

#4
tr -cd ‘[:alnum:]‘ < /dev/urandom | fold -w30 | head -n1

#5
strings /dev/urandom | grep -o ‘[[:alnum:]]’ | head -n 30 | tr -d ‘\n’; echo
通过过滤字符命令,输出随机密码

#6
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
这个命令比起来比较简单了

#7
dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev
上述命令使用命令dd的强大功能

#8
</dev/urandom tr -dc ’12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB’ | head -c8; echo “”

上述命令输出很简洁

#9
randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}

使用randpw随时产生随机密码,可以把它放到~/.bashrc文件里面。

(我这里没有什么密码产生,可留言讨论)

#10
date | md5sum
这个够简单

【参考引用】
[url]http://os.51cto.com/art/201102/246360.htm[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值