linux用户密码生成
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用户密码生成的更多相关文章
- Linux用户密码策略
使用Linux快三年了,从未想过Linux用户密码策略,从未把一本Linux的书从头看到尾(上学时的教材除外),故不知书上有无介绍,直到最近参加公司的信息安全稽核会议后才开始考虑Linux用户密码策略 ...
- 修改linux用户密码
对于初学者来说,如何修改linux用户密码也不是件容易的事,其实非常简单,下面举例说明: 如果是以root身份登录,修改root密码.只要输入 passwd 就会出现: New password: ...
- Linux用户密码期限修改
今天有开发报故,sftp无法登录.检查服务都是正常的,之前3月份也出现过此问题,当时忙没有注意,现在看每3个月出现问题.这才想到是密码过期导致的. 先重置用户密码,发现过期日志为Oct 08, 201 ...
- 忘记Linux用户密码怎么办?
忘记密码解决办法(centos6.5版本) 1.开机时,在此页面一直按ESC 2.然后进入以下界面时,按一下字母 “E” 键 (3)再按字母 “E” 键 (4)之后 输入 ...
- linux用户密码过期导致命令执行失败
背景介绍: 使用zabbix调用系统命令,检查时间同步,发现一直在报错,root 用户执行无异常,问题还是出现zabbix用户上面. [zabbix@test-10-12 ~]$ sudo ntpda ...
- Linux用户密码文件/etc/shadow相关
(1).密码文件 [root@xuexi ~]# head -3 /etc/shadow root:$6$kcgcu794R0VP3fDL$aYN8XUbtWvZ4QQtT2xVW.N2CgE3YLP ...
- Linux用户密码重置方法
方法一: 启动时,随便按一个键,空格即可(不能是回车),让其停留在如下界面 按e编辑 在UTF-8后面添加init=/bin/sh init=/bin/sh 根据上面提示,按Ctrl+x启动得下图 输 ...
- changepassword.c 0.9:一个通过WEB界面更改LINUX用户密码的程序
偶然看到一个用C语言写的CGI程序,可以以WEB界面(无需单独再写HTML)的方式修改用户自己的密码.该程序具有同时修改samba及squid密码的能力. 步骤: 1.下载并解压,并读一下README ...
- linux 用户密码过期时间
/etc/login.defs 全局配置文件,即当新建用户时的默认设置 PASS_MIN_DAYS 5 #最近一次密码更新的日期+0 ,即允许用户更改自己的密码的日期 PASS_MAX_ ...
随机推荐
- python 文件操作与集合
对文件的操作 1.打开文件,获取句柄 2.根据句柄操作文件 3.关闭文件 现有文档 poem.txt 一天很短, 短得来不及拥抱清晨, 就已经手握黄昏. 一年很短, 短得来不及细品初春殷红窦绿, 就要 ...
- iOS开发 Swift开发数独游戏(五)显示游戏答案
要点是设置好Tag就好,通过代码找到并初始化即可. 1: // 2: // ShowAnswerController.swift 3: // sudoku-v02 4: // 5: // ...
- Matlab中struct的用法
struct在matlab中是用来建立结构体数组的.通常有两种用法: s = struct('field1',{},'field2',{},...) 这是建立一个空的结构体,field1,field ...
- Delphi 窗体失踪在最上面的代码
unit ufrmSysPubMessage; interface uses Windows, Forms, Messages, Classes, ExtCtrls, Controls, StdCt ...
- 【sql】关联查询+表自关联查询
表: 经销商 dealer 字段 uid parent_uid name 联系人 contact 字段 uid dealer_id contact_main 需求: 想要查询到经销商的信 ...
- Scut游戏服务器免费开源框架--快速开发(3)
Scut快速开发(3) 1 开发环境 Scut Lib版本:5.2.3.2 需要安装的软件 a) IIS和消息队列(MSMQ) b) 数据库,Sql2005以上版本 ...
- Dedecms getip()的漏洞利用
flyh4t在非安全发布了dedecms getip()的注射漏洞,漏洞本身的成因没什么好说的老掉牙的X-Forwarded-For的问题,我想这个漏洞很多人都找到了,不过这个漏洞的利用有个地方还是可 ...
- centos7修改yum下载源为阿里源
在国内很多yum源不好用,所以改成国内的源很有必要 首先,切换到yum源目录 cd /etc/yum.repos.d 备份一下 sudo mv CentOS-Base.repo CentOS-Base ...
- 蓝点通用管理系统V13版发布了!
蓝点通用管理系统13版已发布! 重磅新功能:系统的通知和提醒功能,增加微信方式,微信通知.微信查询数据.微信拍照上传....... 蓝点的客户管理系统.进销存管理系统.产品管理系统.工作流管理系统.投 ...
- 阿里云部署Java web项目初体验
林炳文Evankaka原创作品. 转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要讲了怎样在阿里云上安装JDK.Tomcat以及其配置过程. 最后以一个实例来演 ...