500、Linux获取随机密码
2016-05-04 10:40
483 查看
1、通过md5sum
[oldboy@oldboy ~]$ date | md5sum 0c0224bab3b2253d03680df246f2244c -
2、通过urandom
[root@oldboy ~]# head -1 /dev/urandom | cksum 3464856893 212
3、通过环境变量获取
[oldboy@oldboy ~]$ echo ${RANDOM} 21524 [oldboy@oldboy ~]$ echo ${RANDOM} 5722 [oldboy@oldboy ~]$ echo ${RANDOM} 4910
4、获取定长随机密码
[stu09@oldboy ~]$ date | md5sum f125f769f6a793c383c5ed343e75bb35 - [stu09@oldboy ~]$ date | md5sum | cut -c 1-8 # 方法1 6d4b2274 [stu09@oldboy ~]$ head -1 /dev/urandom | cksum 4195806788 8 [stu09@oldboy ~]$ head -1 /dev/urandom | cksum | cut -c 1-8 # 方法2 17477213
5、示例:批量创建10个用户stu01-stu10,并且设置随机8位密码,要求不能用shell的循环(例如:for,while等),只能用linux命令及管道实现。
[root@oldboy ~]# head -1 /dev/urandom | cksum | cut -c 1-8 ##获取8位随机数 31837928 [root@oldboy ~]# head -1 /dev/urandom | cksum | cut -c 1-8 ##获取8位随机数 18928057 [root@oldboy ~]# head -1 /dev/urandom | cksum | cut -c 1-8 ##获取8位随机数 10311251 [root@oldboy ~]# echo stu{01..10} | xargs -n 1 | awk '{print "useradd "$0"; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin "$0'} useradd stu01; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin stu01 useradd stu02; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin stu02 useradd stu03; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin stu03 useradd stu04; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin stu04 useradd stu05; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin stu05 useradd stu06; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin stu06 useradd stu07; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin stu07 useradd stu08; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin stu08 useradd stu09; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin stu09 useradd stu10; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin stu10 [root@oldboy ~]# echo stu{01..10} | xargs -n 1 | awk '{print "useradd "$0"; echo `head -200 /dev/urandom | cksum | cut -c 1-8` | passwd --stdin "$0'} | bash ### 但是不知道每个用户的登录密码 Changing password for user stu01. passwd: all authentication tokens updated successfully. Changing password for user stu02. passwd: all authentication tokens updated successfully. Changing password for user stu03. passwd: all authentication tokens updated successfully. Changing password for user stu04. passwd: all authentication tokens updated successfully. Changing password for user stu05. passwd: all authentication tokens updated successfully. Changing password for user stu06. passwd: all authentication tokens updated successfully. Changing password for user stu07. passwd: all authentication tokens updated successfully. Changing password for user stu08. passwd: all authentication tokens updated successfully. Changing password for user stu09. passwd: all authentication tokens updated successfully. Changing password for user stu10. passwd: all authentication tokens updated successfully. [root@oldboy ~]# echo stu{01..10} | xargs -n 1 | awk '{print "useradd "$0"; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin "$0 '} useradd stu01; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin stu01 useradd stu02; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin stu02 useradd stu03; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin stu03 useradd stu04; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin stu04 useradd stu05; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin stu05 useradd stu06; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin stu06 useradd stu07; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin stu07 useradd stu08; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin stu08 useradd stu09; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin stu09 useradd stu10; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin stu10 [root@oldboy ~]# echo stu{01..10} | xargs -n 1 | awk '{print "useradd "$0"; userpasswd=`head -1 /dev/urandom | cksum | cut -c 1-8`; echo ${userpasswd} >> passwd.log; echo ${userpasswd} | passwd --stdin "$0 '} | bash ###将密码保存在当前目录的passwd.log中,可根据里面的密码进行登录 Changing password for user stu01. passwd: all authentication tokens updated successfully. Changing password for user stu02. passwd: all authentication tokens updated successfully. Changing password for user stu03. passwd: all authentication tokens updated successfully. Changing password for user stu04. passwd: all authentication tokens updated successfully. Changing password for user stu05. passwd: all authentication tokens updated successfully. Changing password for user stu06. passwd: all authentication tokens updated successfully. Changing password for user stu07. passwd: all authentication tokens updated successfully. Changing password for user stu08. passwd: all authentication tokens updated successfully. Changing password for user stu09. passwd: all authentication tokens updated successfully. Changing password for user stu10. passwd: all authentication tokens updated successfully. [root@oldboy ~]# cat passwd.log # 密码信息 40814279 18955776 52266806 13477959 32334090 22175853 58152844 21678445 13336223 25331082
另请参考:linux实战考试题:批量创建用户和密码-看看你会么?
相关文章推荐
- Linux(CentOS 6.7)下配置Mono和Jexus并且部署ASP.NET MVC3、4、5和WebApi(跨平台)
- linux下的tar命令
- linux批量删除进程
- Linux git服务搭建
- CentOS6.5搭建SVN配置教程
- linux学习笔记 - grep
- linux字节
- linux学习笔记 - TOP
- linux怎样修改主机名
- 转 -Linux 自检和 SystemTap (强大的内核调试工具)---包含下载地址
- 每天一个Linux命令(6)rmdir命令
- 在基于ZedBoard的Linux系统下添加自定义硬件IP(1)——启动Linux系统
- linux系统启动过程
- Linux 如何在 vi 里搜索关键字
- hadoop转自马哥linux
- Linux控制进程实战fork /vfork
- Linux进程之alarm()信号传送闹钟函数
- linux安装配置jdk
- Centos安装php高版本
- Linux软件包管理基本操作入门