SaltStack 用户管理

SaltStack拥有非常多的模块,功能很强大。其中salt.states.user这个模块可以帮助我们更方便管理服务器用户权限。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
root:
user.present:
- shell: /bin/bash
- passwd: 'xxxxxxxxxxxxxxxxxxx'
- uid: 0
- gid: 0
- require:
- group: root
group.present:
- gid: 0
admin:
user.absent
/root/.ssh/authorized_keys:
file.managed:
- source: salt://files/.ssh/root_authorized_keys
- user: root
- group: root
1
2
$ openssl passwd -1 -salt 'root'
Password:

输入密码后会生成一串md5值,替换上面配置文件中的xxx。

1
$ salt 'target' state.sls user.sls

推送到客户端生效。

另外Salt有专门的模块来管理SSH证书,这里先用文件管理的土办法。TODO