理解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等映像文件 ...
随机推荐
- k8s cronjob设置作业失败后退出不重复执行
Optional parameters backoffLimit: Number of retries for pods launched by the job. If you want your p ...
- Navicat Win 和 Mac 视图类快捷键对比
Navicat 查询是根据用户需求从数据库提取可读格式的数据,Navicat 提供两个强大的工具与 SQL 查询工作:查询创建工具和查询编辑器,查询创建工具可视觉化地创建查询,查询编辑器可直接编辑查询 ...
- PHP访问SQL Server驱动对应关系
引用地址: https://docs.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?vi ...
- 19.翻译系列:EF 6中定义自定义的约定【EF 6 Code-First约定】
原文链接:https://www.entityframeworktutorial.net/entityframework6/custom-conventions-codefirst.aspx EF 6 ...
- C# yield return; yield break;
using System; using System.Collections; namespace YieldDemo { class Program { public static IEnumera ...
- 文档大师 在Win10 IE11下,文档集画面无法正常显示Word等Office文档的解决方法
在文档集界面中显示Word文档,是文档大师的一个核心功能. 最近在 Win10 升级到最新版后,发现 无法正常显示Office 文档的问题. 一开始以为是Word版本问题,从2007升级到2016,问 ...
- Unable to find IPv4-only network bridge for LXD.
https://github.com/conjure-up/conjure-up/issues/1440It seems like the the installation is complainin ...
- C语言 · 猜算式
题目:猜算式 看下面的算式: □□ x □□ = □□ x □□□ 它表示:两个两位数相乘等于一个两位数乘以一个三位数. 如果没有限定条件,这样的例子很多. 但目前的限定是:这9个方块,表示1~9的9 ...
- 第四百零四节,python网站第三方登录,social-auth-app-django模块,
第四百零四节,python网站第三方登录,social-auth-app-django模块, social-auth-app-django模块是专门用于Django的第三方登录OAuth2协议模块 目 ...
- [转]SpringMVC+ Mybatis 配置多数据源 + 手动切换数据源
正确可行的解决方法:使用Spring提供的AbstractRoutingDataSource类来根据请求路由到不同的数据源.具体做法是先设置两个不同的dataSource代表不同的数据源,再建一个总的 ...