Linux之一句话shell生成随机密码和生成shadow格式用的密码

摘要

有时候为了生成一个随机密码,确实很头疼的。这里做下汇总

[root@Linode-JP-35 ~]# cat /dev/urandom | awk 'NR==1{print $0|"md5sum|base64|grep -Eo '^.{16}'";exit}'
YWFhMzA4MmQ4YjBk
[root@Linode-JP-35 ~]# < /dev/urandom awk 'NR==1{print $0|"md5sum|base64|grep -Eo '^.{16}'";exit}'
ODc1ZTQzYTNkYjQ1
[root@Linode-JP-35 ~]# od -N8 -tx8 /dev/random | awk 'NR==1{print $NF}'
9404172875d9c080
[root@Linode-JP-35 ~]# cat /dev/urandom | awk 'NR==1{print $0|"md5sum|head -c 16";exit}';echo
dc836360f4ce5c02
[root@Linode-JP-35 ~]# echo "$(date +%s)"|sha256sum|base64|head -c 16;echo
YmQzNmRhNDYwNTYx
[root@Linode-JP-35 ~]# mkpasswd -l 16 -d 5 -C 5
E5s{2g7yQM7NHgf5
[root@Linode-JP-35 ~]# < /dev/urandom tr -dc A-Z-a-z-0-9 | head -c${1:-16};echo;
XLGoh2gLkvZTn1o9
[root@Linode-JP-35 ~]# openssl rand -hex 8
f43a35be7dc0122b
[root@Linode-JP-35 ~]# dd if=/dev/urandom bs=1 count=32 2>/dev/null |base64|head -c16;echo
kuH3aB5lcPP4IPAp
[root@Linode-JP-35 ~]# 

生成Linux系统上shadow文件格式的密码

[root@Linode-JP-35 ~]# perl -e 'print crypt("password","\$6\$salt\$") . "\n"'
$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.
[root@Linode-JP-35 ~]# python -c "import crypt, getpass, pwd;print crypt.crypt('password', '\$6\$saltsalt\$')"
$6$saltsalt$qFmFH.bQmmtXzyBY0s9v7Oicd2z4XSIecDzlB5KiA2/jctKu9YterLp8wwnSq.qc.eoxqOmSuNp2xS0ktL3nh/
[root@Linode-JP-35 ~]# python -c "import crypt, getpass, pwd; print crypt.crypt(raw_input(), '\$6\$' + raw_input() + '\$')"
lookback
saltsalt
$6$saltsalt$a0J/T8m/LXCZ3GWU2k8doYlZYN63LQj7MJnPST15U/v.RpsP5vnt0qtkByqSO/fVa0Qby6BDIi.J94pt3RmKz.
[root@Linode-JP-35 ~]# python -c "import crypt, getpass;print crypt.crypt('password')" #上面都是指定salt的,这个就是随机加盐的
$6$hppfi2m5kPwuxG.e$c8IWMJKk6qo8NSdV6sMghnSPolow7ngvQoKlMw6bH/BYogWmExsnxCMVSkVNJdn3jPhQPF/s7t5KkDFiJ3IjU0
[root@Linode-JP-35 ~]# 

上述方法在MAC系统上是不行的,下面的方法才可以

[lookback@lookbackdeMacBook-Pro ~]$ pip install passlib
[lookback@lookbackdeMacBook-Pro ~]$ python -c "from passlib.hash import sha512_crypt; print (sha512_crypt.encrypt('lookback', rounds=5000))"
$6$I63m/Yu0.SRhuR./$1w.LfbsMczJQfJt9xukv054kC74XOsram8f.aAgzCVdOgsBV3ew/rqQhlNBXWpNWSZZgH9umFtM2y7/HG9A9o1

[lookback@lookbackdeMacBook-Pro ~]$ Password=$(date +"%s%N"| sha256sum | base64 | head -c 24) && python3 -c "from passlib.hash import sha512_crypt; print(sha512_crypt.encrypt('${Password}', rounds=5000))" && echo $Password
$6$5s0hSb/KwZh5jeIm$XCv24cSN6mIiyKPRyu64kSgok0HisfxCAKAeNaVKcmt8FKmnjLN/R6WTbmp.8S1/NnH27Yv6cnLEFkZbhFUVk1
ODM4NzI5ZGVmY2M5NGU0NTk3
lookback
  • 本文由 发表于 2015年7月26日05:50:02
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

评论:1   其中:访客  1   博主  0
    • 追梦 追梦 1

      http://www.zmrbk.com/tool/pass 在线生成随机密码