1. 传统上,linux把加密(哈希)的密码保存在/etc/passwd文件中,passwd文件的格式如下:

smithj:x:561:561:Joe Smith:/home/smithj:/bin/bash

共7个字段,由":"分隔, 各字段的含义如下:

  1. smithj, Username, up to 8 characters. Case-sensitive, usually all lowercase
  2. 加密后的密码,空表示没有密码;“x"表示密码保存在/etc/shadow文件中。
  3. 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.
  4. 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.
  5. 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).
  6. User's home directory. Usually /home/username (eg. /home/smithj). All user's personal files, web pages, mail forwarding, etc. will be stored here.
  7. 用户的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:::

  1. Username, up to 8 characters. Case-sensitive, usually all lowercase. A direct match to the username in the /etc/passwd file.
  2. 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.
  3. The number of days (since January 1, 1970) since the password was last changed.
  4. The number of days before password may be changed (0 indicates it may be changed at any time)
  5. The number of days after which password must be changed (99999 indicates user can keep his or her password unchanged for many, many years)
  6. The number of days to warn user of an expiring password (7 for a full week)
  7. The number of days after password expires that account is disabled
  8. The number of days since January 1, 1970 that an account has been disabled
  9. A reserved field for possible future use

3. 密码字段的格式:

密码字段分为三个部分,由$分隔:

$加密算法代号$盐值$密文

  • 加密算法:
  1. $1$ is MD5
  2. $2a$ is Blowfish
  3. $2y$ is Blowfish
  4. $5$ is SHA-256
  5. $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 密码存储的更多相关文章

  1. 深入理解linux系统下proc文件系统内容

    深入理解linux系统下proc文件系统内容 内容摘要:Linux系统上的/proc目录是一种文件系统,即proc文件系统. Linux系统上的/proc目录是一种文件系统,即proc文件系统.与其它 ...

  2. 深入理解Linux中内存管理

    前一段时间看了<深入理解Linux内核>对其中的内存管理部分花了不少时间,但是还是有很多问题不是很清楚,最近又花了一些时间复习了一下,在这里记录下自己的理解和对Linux中内存管理的一些看 ...

  3. 理解 Linux 配置文件分类和使用

    理解 Linux 配置文件分类和使用 本文说明了 Linux 系统的配置文件,在多用户.多任务环境中,配置文件控制用户权限.系统应用程序.守护进程.服务和其它管理任务.这些任务包括管理用户帐号.分配磁 ...

  4. 深入理解Linux内存分配

    深入理解Linux内存分配 为了写一个用户层程序,你也许会声明一个全局变量,这个全局变量可能是一个int类型也可能是一个数组,而声明之后你有可能会先初始化它,也有可能放在之后用到它的时候再初始化.除此 ...

  5. 读书笔记之Linux系统编程与深入理解Linux内核

    前言 本人再看深入理解Linux内核的时候发现比较难懂,看了Linux系统编程一说后,觉得Linux系统编程还是简单易懂些,并且两本书都是讲Linux比较底层的东西,只不过侧重点不同,本文就以Linu ...

  6. 理解linux sed命令

    理解linux sed命令(2010-02-27 18:21:20) 标签:linuxshellsed替换 分类:革命本钱 1. Sed简介sed是一种在线编辑器,它一次处理一行内容.处理时,把当 前 ...

  7. 使用John the ripper工具来尝试破解Linux密码

    这篇文章主要介绍了使用John the ripper工具来尝试破解Linux密码的方法,这款工具可能主要被用来破解系统用户的密码以获得文件操作权限,需要的朋友可以参考下 John有别于Hdra之类的工 ...

  8. 从需求的角度去理解Linux系列:总线、设备和驱动

    笔者成为博客专家后整理以前原创的嵌入式Linux系列博文,现推出以让更多的读者受益. <从需求的角度去理解linux系列:总线.设备和驱动>是一篇有关如何学习嵌入式Linux系统的方法论文 ...

  9. 深入理解Linux启动过程

    深入理解Linux启动过程       本文详细分析了Linux桌面操作系统的启动过程,涉及到BIOS系统.LILO 和GRUB引导装载程序,以及bootsect.setup.vmlinux等映像文件 ...

随机推荐

  1. 全栈JavaScript之路(十九)HTML5 插入 html标记 ( 一 )innerHTML 与outerHTML

    在须要给文档插入大量的html 标记下.通过DOM操作非常麻烦,你不仅要创建一系列的节点,并且还要小心地依照顺序把它们接结起来. 利用html 标签 插入技术,能够直接插入html代码字符串,简单.高 ...

  2. vue:资源小记

    github: https://github.com/keenleung/vue-tutorials 过滤器: https://segmentfault.com/a/1190000005027001 ...

  3. mysql多实例配置下,用脚本启动mysql时,出现Please read "Security" section of the manual to find out how to run mysqld as root!

    [root@localhost 3308]# mysqld stop170414 0:35:28 [Note] --secure-file-priv is set to NULL. Operation ...

  4. iOS开发之资料收集

    github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自github:https://github ...

  5. 关于在最新的 Visual Studio 2017 版本中使用 Web Deploy 遇到的 SSL 连接错误

    错误信息: 无法完成向远程代理 URL 发送请求.请求被中止: 未能创建 SSL/TLS 安全通道. 原因分析: 最新版本的 Visual Studio 中,已经抛弃了 https 协议中旧版 SSL ...

  6. MySQL InnoDB 引擎的持久性与性能

    MySQL 事务的 ACID 特性中,D 代表持久性(Durability):在使用 InnoDB 引擎时,当返回客户端一个成功完成事务的确认时, InnoDB 就会保证数据的一致性,即使该数据在此时 ...

  7. virtualbox安装android6.0并设置分辨率为1920x1080x32

    下载安装:https://www.cnblogs.com/wynn0123/p/6288344.html 这里我做的是下载android6.0-64bit,然后文件系统只支持ext4 安装完成之后我的 ...

  8. jinfo

    jinfo是jdk自带的命令,用来查看.修改jvm的配置参数. [weblogic@host bin]$ jinfo-bash: jinfo: command not found[weblogic@h ...

  9. linux下pppoe连接管理

    一.安装pppoe组件 sudo apt-get install pppoe pppoeconf 二.配置pppoe 图形界面配置pppoe,在terminal里输入 nm-connection-ed ...

  10. 简单探讨spring整合mybatis时sqlSession不需要释放关闭的问题

    https://blog.csdn.net/RicardoDing/article/details/79899686 近期,在使用spring和mybatis框架编写代码时,sqlSession不需要 ...