【发布时间】:2020-04-11 12:19:43
【问题描述】:
关于.ssh/authorized_keys 上的权利问题,我的大脑正在纠结。
我的 ansible 脚本非常适合在我的服务器上创建用户,我只想修改 /home/user、/home/user/.ssh 和最后 /home/user.ssh/authorized_keys 的权限,因为默认情况下它们不正确。
我找不到问题出在哪里。
---
- hosts: all
become: true
tasks:
- name: Creation groupe dev
group:
name: dev
state: present
- name: Creation des utilisateurs
user:
name: "{{ item.path }}"
group: dev
state: present
password: "{{ lookup('password', '/dev/null') |password_hash('sha512') }}"
update_password: on_create
with_filetree: xx_pub_keys/
- name: copie des clés SSH
authorized_key:
user: "{{ item.path }}"
key: "{{ lookup('file', 'xx_pub_keys/' + item.path ) }}"
state: present
with_filetree: xx_pub_keys/
- name: droits repertoires
command:
chmod go-w /home/{{ user.path }} && \
chmod 700 /home/{{ user.path }} && \
chmod 644 /home/{{ user.path }}/.ssh/authorized_keys
- name: "Suppression des users eventuels"
user:
name: "{{ item.path }}"
state: absent
remove: true
with_filetree: xx_pub_remove/
- name: Allow admin users to sudo without a password
lineinfile:
dest: "/etc/sudoers"
state: "present"
regexp: "^%admin"
line: "%admin ALL=(ALL) NOPASSWD: ALL"
- name: restart sshd
service: name=ssh state=restarted ...
所以我在“目录权限”部分尝试了user.path,item.path,带有with_items 的短项...
我不知道...
简而言之,我赞成任何更正。
提前谢谢你
【问题讨论】:
-
“默认不正确”是什么意思?你会期待什么,你实际得到什么?
-
您能否编辑帖子以使 Ansible 剧本更具可读性?将其“作为代码”发布
-
authorized_keys 不是 0644 。
root@zen:/home# ls -la total 56 drwxr-xr-x 3 user1 dev 4096 avril 10 14:41 user1 => manually changed drwxrwxr-x 2 user2 dev 4096 avril 9 14:01 user2 => ansible install root@zen:/home# ls -la user2/ drwx------ 2 user2 dev 4096 avril 10 15:18 .ssh root@zen:/home# ls -la s.user2/.ssh/ -rw------- 1 user2 dev 400 avril 10 15:18 authorized_keys And for user1 : -rw-r--r-- 1 user1 dev 222 avril 10 14:41 authorized_keys -
对不起代码格式...
标签: ansible rights authorized-keys