理解linux 密码存储
1. 传统上,linux把加密(哈希)的密码保存在/etc/passwd文件中,passwd文件的格式如下:
smithj:x:561:561:Joe Smith:/home/smithj:/bin/bash
共7个字段,由":"分隔, 各字段的含义如下:
- smithj, Username, up to 8 characters. Case-sensitive, usually all lowercase
- 加密后的密码,空表示没有密码;“x"表示密码保存在/etc/shadow文件中。
- Numeric user id. This is assigned by the ``adduser'' script. Unix uses this field, plus the following group field, to identify which files belong to the user.
- Numeric group id. Red Hat uses group id's in a fairly unique manner for enhanced file security. Usually the group id will match the user id.
- Full name of user. I'm not sure what the maximum length for this field is, but try to keep it reasonable (under 30 characters).
- User's home directory. Usually /home/username (eg. /home/smithj). All user's personal files, web pages, mail forwarding, etc. will be stored here.
- 用户的shell. Often set to ``/bin/bash'' to provide access to the bash shell
2. /etc/shadow文件详解
shadow文件的每一行定义一个用户,共九个字段,格式如下:
{用户名}:{加密后的口令密码}:{口令最后修改时间距原点(1970-1-1)的天数}:{口令最小修改间隔(防止修改口令,如果时限未到,将恢复至旧口令):{口令最大修改间隔}:{口令失效前的警告天数}:{账户不活动天数}:{账号失效天数}:{保留}
例如:
root:$6$4rSdQWBy$970A61Zc6.5b1Ioh2Sl3dj/EbpKChilvqPsQz3h78YhcYnVoPQ9xXZeABlRLpfFsgTX0dlegSpC56LLqCPje41:0:0:99999:7:::
- Username, up to 8 characters. Case-sensitive, usually all lowercase. A direct match to the username in the /etc/passwd file.
- Password, 13 character encrypted. A blank entry (eg. ::) indicates a password is not required to log in (usually a bad idea), and a ``*'' entry (eg. :*:) indicates the account has been disabled.
- The number of days (since January 1, 1970) since the password was last changed.
- The number of days before password may be changed (0 indicates it may be changed at any time)
- The number of days after which password must be changed (99999 indicates user can keep his or her password unchanged for many, many years)
- The number of days to warn user of an expiring password (7 for a full week)
- The number of days after password expires that account is disabled
- The number of days since January 1, 1970 that an account has been disabled
- A reserved field for possible future use
3. 密码字段的格式:
密码字段分为三个部分,由$分隔:
$加密算法代号$盐值$密文
- 加密算法:
- $1$ is MD5
- $2a$ is Blowfish
- $2y$ is Blowfish
- $5$ is SHA-256
- $6$ is SHA-512
- 盐值
盐值的位数与加密算法有关,以SHA-512为例,盐值是一个base64的随机串,串的长度是8~16的随机数。
linux中加密由crypt()函数实现,crypt()会调用crypt_make_salt()函数生成盐值。盐值长度是一个个随机数,由shadow_random(8,16)函数产生。因此,linux中加密密码的盐值的位数由程序自动生成,是不可配的。除非修改源码。
crypt_make_salt()--->gensalt(salt_size)---->l64a(random())生成base64编码的,长度为salt_size的盐值字符串。
- 密文
盐值+密码(明文)通过加密算法得到的字符串(base64)。
理解linux 密码存储的更多相关文章
- 深入理解linux系统下proc文件系统内容
深入理解linux系统下proc文件系统内容 内容摘要:Linux系统上的/proc目录是一种文件系统,即proc文件系统. Linux系统上的/proc目录是一种文件系统,即proc文件系统.与其它 ...
- 深入理解Linux中内存管理
前一段时间看了<深入理解Linux内核>对其中的内存管理部分花了不少时间,但是还是有很多问题不是很清楚,最近又花了一些时间复习了一下,在这里记录下自己的理解和对Linux中内存管理的一些看 ...
- 理解 Linux 配置文件分类和使用
理解 Linux 配置文件分类和使用 本文说明了 Linux 系统的配置文件,在多用户.多任务环境中,配置文件控制用户权限.系统应用程序.守护进程.服务和其它管理任务.这些任务包括管理用户帐号.分配磁 ...
- 深入理解Linux内存分配
深入理解Linux内存分配 为了写一个用户层程序,你也许会声明一个全局变量,这个全局变量可能是一个int类型也可能是一个数组,而声明之后你有可能会先初始化它,也有可能放在之后用到它的时候再初始化.除此 ...
- 读书笔记之Linux系统编程与深入理解Linux内核
前言 本人再看深入理解Linux内核的时候发现比较难懂,看了Linux系统编程一说后,觉得Linux系统编程还是简单易懂些,并且两本书都是讲Linux比较底层的东西,只不过侧重点不同,本文就以Linu ...
- 理解linux sed命令
理解linux sed命令(2010-02-27 18:21:20) 标签:linuxshellsed替换 分类:革命本钱 1. Sed简介sed是一种在线编辑器,它一次处理一行内容.处理时,把当 前 ...
- 使用John the ripper工具来尝试破解Linux密码
这篇文章主要介绍了使用John the ripper工具来尝试破解Linux密码的方法,这款工具可能主要被用来破解系统用户的密码以获得文件操作权限,需要的朋友可以参考下 John有别于Hdra之类的工 ...
- 从需求的角度去理解Linux系列:总线、设备和驱动
笔者成为博客专家后整理以前原创的嵌入式Linux系列博文,现推出以让更多的读者受益. <从需求的角度去理解linux系列:总线.设备和驱动>是一篇有关如何学习嵌入式Linux系统的方法论文 ...
- 深入理解Linux启动过程
深入理解Linux启动过程 本文详细分析了Linux桌面操作系统的启动过程,涉及到BIOS系统.LILO 和GRUB引导装载程序,以及bootsect.setup.vmlinux等映像文件 ...
随机推荐
- ffmpeg 、Vlc参数
ffmpeg.exe -loglevel error -probesize 32 -vsync passthrough -framerate 20 -f gdigrab -i desktop -fil ...
- Canvas入门到高级详解(上)
神奇的 canvas--AICODER 全栈培训 IT 培训专家 一.canvas 简介 1.1 什么是 canvas?(了解) 是 HTML5 提供的一种新标签 <canvas>< ...
- eclipse下安装windowbuilder(一定要看)
访问页面https://www.eclipse.org/windowbuilder/download.php,查看更新连接 这个是**连接地址**,要复制粘贴到eclipse里. !! 复制地址!!
- Sqlmap 中绕过空格拦截的12个脚本
- 【iCore4 双核心板_ARM】例程二十四:LWIP_DHCP实验——动态分配IP地址
实验现象: 核心代码: int main(void) { system_clock.initialize(); led.initialize(); adc.initialize(); delay.in ...
- Efficient Online Segmentation for Sparse 3D Laser Scans-- 在线的稀疏点云分割
在基于激光的自动驾驶或者移动机器人的应用中,在移动场景中提取单个对象的能力是十分重要的.因为这样的系统需要在动态的感知环境中感知到周围发生变化或者移动的对象,在感知系统中,将图像或者点云数据预处理成单 ...
- Android 解析未知格式的json数据
1.递归一有的时候我们需要解析未知的json.或者说是动态的json.那么我们并不知道key具体是多少,或者说key不是固定的.这时候就需要解析动态key的方法. 这个方法是我在实现解析前台传入的js ...
- 31Spring的一些想法
看一遍以前的自己写的博客,记录下自己的一些想法,Spring分为两块:IOC和AOP.IOC就是在applicatcontext.xml中配置<<bean......>>这种. ...
- A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' or 'http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider' was not present on the pro
Try setting (in global.cs): AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier; ...
- 基金 、社保和QFII等机构的重仓股排名评测
基金前15大重仓股持仓股排名 基金重仓前15大个股,相较于同期沪深300的平均收益, 近1月:2.45%, 近3月:10.0%, 近1年:11.22%, 近3年:105.23%. 1,中国平安(SH6 ...