salt的用户管理。
添加单个用户:
[root@test1 user]# pwd
/srv/salt/base/user
[root@test1 user]# cat user.sls
wenji:
user.present: ## 这个选项必须有,表示创建用户
- fullname: action wenji ## 用户的完整名称
- password: '$1$kora$snhVYZZOEb5ga.FZBRB500' ## 为用户指定密码
- shell: /bin/bash ## 指定用户的登录shell
- home: /home/wenji ## 指定用户的家目录
- uid: 1110 ## 指定UID
- gid_from_name: true ## 让GID和用户的UID保持一致,即使用默认的组
添加用户组:
[root@test1 user]# cat group.sls
wenji:
group.present:
- gid: 601
yunwei:
group.present:
- gid: 602
生成密码
openssl passwd -1-salt 'wenji'
批量添加用户
[root@test1 user]# cat users.sls
{% set users = ['wenji1','wenji2','wenji3'] %}
{% for user in users %}
` user `:
user.present:
- shell: /bin/bash
- home: /home/` user `
- password: '$1$linwangy$PMII.NL0igptfGBV0PtxI1'
- gid: 601
- groups:
- wenji
{% endfor %}
批量修改用户:
生成密码
[iyunv@test1 salt]# openssl passwd -1
Password:
Verifying - Password:
$1$h6niwjpG$2nAnRib36QUr2wnfYXC4u0
userpasswd.sls文件:
[iyunv@test1 salt]# cat user/userpasswd.sls
{% set users = ['wenji1','wenji2','wenji3'] %}
{% for user in users %}
` user `:
user.present:
- shell: /bin/bash
- password: '$1$h6niwjpG$2nAnRib36QUr2wnfYXC4u0'
{% endfor %}
参考资料