linux账户保存在/etc/passwd,密码保存在/etc/shadow。

通过man 5 passwd,man 5 shadow可查看文件中各字段含义。

encrypted password
           Refer to crypt(3) for details on how this string is interpreted.
密码是通过库函数crypt生成的。

1. 函数

#define _XOPEN_SOURCE       /* See feature_test_macros(7) */
       #include <unistd.h>

char *crypt(const char *key, const char *salt);
输入参数:key为密码,salt本意为盐,为增加密码难度,加把盐。salt有新旧两种方式:

       key is a user's typed password.
salt is a two-character string chosen from the set [a–zA–Z0–./]. This string is used to perturb
the algorithm in one of different ways.
The glibc2 version of this function supports additional encryption algorithms.

       If salt is a character string starting with the characters "$id$" followed by a  string  terminated
by "$": $id$salt$encrypted then instead of using the DES machine, id identifies the encryption method used and this then determines how the rest of the password string is interpreted. The following values of id are supported: ID | Method
─────────────────────────────────────────────────────────
| MD5
2a | Blowfish (not in mainline glibc; added in some
| Linux distributions)
| SHA- (since glibc 2.7)
| SHA- (since glibc 2.7) So $$salt$encrypted is an SHA- encoded password and $$salt$encrypted is an SHA- encoded
one. "salt" stands for the up to characters following "$id$" in the salt. The encrypted part of the password string is the actual computed password. The size of this string is fixed:
MD5 | characters
SHA- | characters
SHA- | characters The characters in "salt" and "encrypted" are drawn from the set [a–zA–Z0–./]. In the MD5 and SHA implementations the entire key is significant (instead of only the first bytes in DES).

现在linux都实现的是第二中方式的salt。

2. coding

#define _XOPEN_SOURCE

#include <stdio.h>
#include <unistd.h> int main(int argc, char*argv[])
{
if(argc != ){
return ;
} printf("%s==%s==%s==\n", argv[], argv[], argv[]); printf("%s\n", crypt(argv[], argv[])); return ;
}

创建test用户,密码test123

test:$$BJIQmFkQ$TnJMVbBoWvE4fBkJ30iJlQwDLxV3wLaZ8pVqrh7N5m0mTWD.vNdRw/uEs8Wu7IB.sfvzBYZUweM6Rd0M43bm61:::::::

程序测试

~$gcc crypt.c -lcrypt
~$./a.out test $$BJIQmFkQ$
./a.out==test==$==
Segmentation fault (core dumped)
~$./a.out test "\$6\$BJIQmFkQ\$"
./a.out==test==$$BJIQmFkQ$==
$$BJIQmFkQ$uIMnVVN/FUac.VGm0Ie6g.gWjIRsE0PSNX8ufDcekvmGZ7PtrLVJbrZTlhYplfyEbonrBYpwvHIWGQx9XxeQG/
~$./a.out test "BJIQmFkQ"
./a.out==test==BJIQmFkQ==
BJp/Gyj8SpEnI
~$./a.out test123 "\$6\$BJIQmFkQ\$"
./a.out==test123==$6$BJIQmFkQ$==
$6$BJIQmFkQ$TnJMVbBoWvE4fBkJ30iJlQwDLxV3wLaZ8pVqrh7N5m0mTWD.vNdRw/uEs8Wu7IB.sfvzBYZUweM6Rd0M43bm61

linux用户密码生成的更多相关文章

  1. Linux用户密码策略

    使用Linux快三年了,从未想过Linux用户密码策略,从未把一本Linux的书从头看到尾(上学时的教材除外),故不知书上有无介绍,直到最近参加公司的信息安全稽核会议后才开始考虑Linux用户密码策略 ...

  2. 修改linux用户密码

    对于初学者来说,如何修改linux用户密码也不是件容易的事,其实非常简单,下面举例说明: 如果是以root身份登录,修改root密码.只要输入 passwd 就会出现: New password:  ...

  3. Linux用户密码期限修改

    今天有开发报故,sftp无法登录.检查服务都是正常的,之前3月份也出现过此问题,当时忙没有注意,现在看每3个月出现问题.这才想到是密码过期导致的. 先重置用户密码,发现过期日志为Oct 08, 201 ...

  4. 忘记Linux用户密码怎么办?

           忘记密码解决办法(centos6.5版本) 1.开机时,在此页面一直按ESC 2.然后进入以下界面时,按一下字母  “E”    键 (3)再按字母   “E”   键 (4)之后 输入 ...

  5. linux用户密码过期导致命令执行失败

    背景介绍: 使用zabbix调用系统命令,检查时间同步,发现一直在报错,root 用户执行无异常,问题还是出现zabbix用户上面. [zabbix@test-10-12 ~]$ sudo ntpda ...

  6. Linux用户密码文件/etc/shadow相关

    (1).密码文件 [root@xuexi ~]# head -3 /etc/shadow root:$6$kcgcu794R0VP3fDL$aYN8XUbtWvZ4QQtT2xVW.N2CgE3YLP ...

  7. Linux用户密码重置方法

    方法一: 启动时,随便按一个键,空格即可(不能是回车),让其停留在如下界面 按e编辑 在UTF-8后面添加init=/bin/sh init=/bin/sh 根据上面提示,按Ctrl+x启动得下图 输 ...

  8. changepassword.c 0.9:一个通过WEB界面更改LINUX用户密码的程序

    偶然看到一个用C语言写的CGI程序,可以以WEB界面(无需单独再写HTML)的方式修改用户自己的密码.该程序具有同时修改samba及squid密码的能力. 步骤: 1.下载并解压,并读一下README ...

  9. linux 用户密码过期时间

    /etc/login.defs    全局配置文件,即当新建用户时的默认设置 PASS_MIN_DAYS  5    #最近一次密码更新的日期+0 ,即允许用户更改自己的密码的日期 PASS_MAX_ ...

随机推荐

  1. Xcode升级后导致插件不能用, 一句代码更新UUID OK~

      find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | ...

  2. IntelliJ IDEA强制更新Maven的包

    1.手动删除Project Settings里面的Libraries内容,[Ctrl]+[Alt]+[Shift]+[S],全选之后点击左上角的减号按钮. 2.在Maven Project的试图里的L ...

  3. JavaScript 中函数节流和函数去抖的讲解

    JavaScript 中函数节流和函数去抖的讲解 我们都知道频繁触发执行一段js逻辑代码对性能会有很大的影响,尤其是在做一些效果实现方面,或者逻辑中需要进行后端请求,更是会导致卡顿,效果失效等结果,所 ...

  4. RenderMonkey 练习 第一天 【opengl 纹理】

    础实例: 我们首先实现一个带纹理模型的显示,大体了解RenderMonkey的操作方式. 1. 打开RenderMonkey, 右击WorkSpace的Effect WorkSpace结点,选择Add ...

  5. html DOM 的继承关系

    零散的知识聚合在一起,就会形成力量,就有了生命力. 如各种语言的开发框架, 都是右各个碎片化的功能聚合在一起,构成有机地整体,便有了强大的力量.will be powerful! 如: jquery ...

  6. ChannelHandlerContext writeAndFlush(firstMessage)

  7. Java定时任务的三种实现方法

    译者注:个人觉得用定时任务来跑垃圾回收不是很好的例子,从译者接触到的项目来看,比较常见的是用定时任务来进行非实时计算,清除临时数据.文件等.在本文里,我会给大家介绍3种不同的实现方法:1.普通thre ...

  8. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-点动面板的每个按钮含义

    参考下面的图示     更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.youku.com/acetaohai123   我的在线论坛: http://csrobot.g ...

  9. Visual studio C++ MFC之点击按钮(菜单栏)生成新窗口

    背景 当前做的APP有菜单栏,菜单栏有一项需要对下位机相关参数进行设置,则必须弹出一个窗口来实现设置操作.本篇即对点击菜单栏生成新的窗口,在新的窗口内完成相应计划后结束新窗口并返回原窗口的方法进行简述 ...

  10. Python趣味实用小工具

    代码地址如下:http://www.demodashi.com/demo/12918.html python 趣味实用小工具 概述 用python实现的三个趣味实用小工具: 图片转Execl工具 , ...