一、批量新增多个用户
1、修改master文件
[[email protected] salt]# vim /etc/salt/master //将下面三行注释去掉
file_roots:
base:
- /srv/salt
2、在/srv/salt目录下创建总入口文件top.sls
[[email protected] salt]# vim /srv/salt/top.sls
[[email protected] salt]# cat /srv/salt/top.sls
base:
'slaver':
- useradds
3、创建useradds.sls
[[email protected] salt]# vim /srv/salt/useradds.sls
[[email protected] salt]# cat /srv/salt/useradds.sls
{% set users = ['jim','hwg','hyxc'] %} #采用jinja语言
{% for user in users %}
{{ user }}:
group.present:
- name: {{ user }}
user.present:
- shell: /bin/bash
- fullname:
- {{ user }}
- password: '$1$sbvWg7.V$r/nWDs7g0YynB1CVsfUPA/'
- groups:
- {{ user }}
{% endfor %}
4、执行命令创建多个用户
[[email protected] salt]# salt 'slaver' state.highstate
由此可见,必须先把用户组创建再来创建用户
二、批量删除多个用户
1、修改top.sls文件
[[email protected] salt]# vim top.sls
[[email protected] salt]# cat top.sls
base:
'slaver':
- userdel
2、创建userdel.sls
[[email protected] salt]# vim userdel.sls
[[email protected] salt]# cat userdel.sls
{% set users = ['jim','hwg','hyxc'] %}
{% for user in users %}
{{ user }}:
user.absent:
- purge: Ture
- force: Ture
{% endfor %}
3、执行删除命令
[[email protected] salt]# salt 'slaver' state.highstate
三、关于用户信息获取的相关命令
1、显示用户密码信息
2、设置或更改用户密码
salt 'slaver' shadow.set_password hwg '$6$hyxchyxc$r2R3uQcnhIl8QSg7WrmojiJqRhD0s6KVYGvXZCswGwW9GDeLF4mhdQJ/Pq8ccWkdzkyYSpxnGqxciMJ53WPI//'
3、删除用户密码,删除后可无密码登陆
[[email protected] salt]# salt 'slaver' shadow.del_password jim slaver: True
4、显示所有用户列表
5、显示指定用户信息