1.添加用户
/srv/salt/top.sls
base: 'test82.salt.cn': - user.useradd
/srv/salt/user/useradd.sls
jim: user.present: - fullname: jim - shell: /bin/bash - password: '$6$hyxchyxc$r2R3uQcnhIl8QSg7WrmojiJqRhD0s6KVYGvXZCswGwW9GDeLF4mhdQJ/Pq8ccWkdzkyYSpxnGqxciMJ53WPI//' - home: /home/jim - uid: 650 - gid: 650 - groups: - jim - root - require: - group: jim group.present: - gid: 650
命令行执行如下命令完成用户创建
salt 'test82.salt.cn' state.highstate
或直接
salt 'test82.salt.cn' state.sls user.useradd
如何生成用户哈希密码?
方法1.可再命令行通过如下命令生产哈希密码
python -c "import crypt; print crypt.crypt('password', '$6$hyxchyxc')"
其中$6代表sha512
哈希类型支持如下几种:
Type Length ====== ====== $6 sha512 128 $5 sha384 96 $4 sha256 64 $3 sha224 56 $2 sha1 40 $1 md5 32
方法2.在命令行执行如下命令
salt 'salt82.test.cn' shadow.gen_password 'password' 默认为sha512
可通过如下设置相应
salt 'salt82.test.cn' shadow.gen_password 'password' crypt_salt'hyxchyxc' algorithm=sha512
2.批量创建用户
/srv/salt/user/usersadd.sls
{% set users = ['jim','hwg','hyxc'] %} {% for user in users %} {{ user }}: user.present: - shell: /bin/bash - password: '$6$hyxchyxc$r2R3uQcnhIl8QSg7WrmojiJqRhD0s6KVYGvXZCswGwW9GDeLF4mhdQJ/Pq8ccWkdzkyYSpxnGqxciMJ53WPI//' - gid: 650 - groups: - jim
{% endfor %}
3.删除用户
/srv/salt/user/userdel.sls
jim: user.absent: - purge: Ture - force: Ture
4.修改用户密码
显示用户密码信息
salt 'test82.salt.cn' shadow.info root
设置或更改用户密码
salt 'test82.salt.cn' shadow.set_password hwg '$6$hyxchyxc$r2R3uQcnhIl8QSg7WrmojiJqRhD0s6KVYGvXZCswGwW9GDeLF4mhdQJ/Pq8ccWkdzkyYSpxnGqxciMJ53WPI//'
删除用户密码,删除后可无密码登陆
salt 'test82.salt.cn' shadow.del_password hwg
5.查看用户信息
显示所有用户列表
salt 'test82.salt.cn' user.list_users
显示指定用户信息
salt 'test82.salt.cn' user.info root
显示用户密码信息
salt 'test82.salt.cn' shadow.info root
-------------------------------------------------------------------------------------------
相关用户管理内置执行命令参见:http://www.cnblogs.com/jim-hwg/p/4610521.html
相关用户组管理内置执行命令参见:http://www.cnblogs.com/jim-hwg/p/4610416.html
相关shadow管理内置执行命令参见:http://www.cnblogs.com/jim-hwg/p/4611157.html