我创建了一个用户,并将 bash 设置为 rbash。在 centos7.x 上,用户可以使用 tab 来补全路径。它在 Ubuntu 20.04 上不起作用,是否需要额外配置?
我使用 ansible playbook 来创建用户:
---
- hosts: all
user: root
gather_facts: true
vars:
limit_user: "programer"
tasks:
- name: "clean dir"
file:
state: absent
path: '/home/{{ limit_user }}/.bin'
- name: "create a directory if it doesn't exist"
file:
state: directory
path: '/home/{{ limit_user }}/.bin'
mode: 0755
group: root
owner: root
- name: "create symbolic link for {{ limit_user }}"
when: ansible_os_family == "RedHat"
file:
state: link
src: '{{ item.src }}'
dest: '{{ item.dest }}'
with_items:
- { src: '/bin/bash', dest: '/bin/rbash' }
- { src: '/usr/bin/ls', dest: '/home/{{ limit_user }}/.bin/ls' }
- { src: '/bin/cat', dest: '/home/{{ limit_user }}/.bin/cat' }
- { src: '/bin/vi', dest: '/home/{{ limit_user }}/.bin/vi' }
- { src: '/bin/tail', dest: '/home/{{ limit_user }}/.bin/tail' }
- { src: '/bin/grep', dest: '/home/{{ limit_user }}/.bin/grep' }
- { src: '/bin/top', dest: '/home/{{ limit_user }}/.bin/top' }
- { src: '/usr/bin/su', dest: '/home/{{ limit_user }}/.bin/su' }
- { src: '/usr/bin/more', dest: '/home/{{ limit_user }}/.bin/more' }
- { src: '/usr/bin/less', dest: '/home/{{ limit_user }}/.bin/less' }
- { src: '/usr/bin/zcat', dest: '/home/{{ limit_user }}/.bin/zcat' }
- { src: '/usr/bin/ps', dest: '/home/{{ limit_user }}/.bin/ps' }
- { src: '/usr/bin/curl', dest: '/home/{{ limit_user }}/.bin/curl' }
- { src: '/usr/bin/stat', dest: '/home/{{ limit_user }}/.bin/stat' }
- { src: '/usr/bin/md5sum', dest: '/home/{{ limit_user }}/.bin/md5sum' }
- { src: '/usr/local/jdk/bin/jstack', dest: '/home/{{ limit_user }}/.bin/jstack' }
- { src: '/usr/local/jdk/bin/jstat', dest: '/home/{{ limit_user }}/.bin/jstat' }
- { src: '/usr/sbin/ifconfig', dest: '/home/{{ limit_user }}/.bin/ifconfig' }
- name: "create symbolic link for {{ limit_user }}"
when: ansible_os_family == "Debian"
file:
state: link
src: '{{ item.src }}'
dest: '{{ item.dest }}'
with_items:
- { src: '/bin/bash', dest: '/bin/rbash' }
- { src: '/bin/su', dest: '/home/{{ limit_user }}/.bin/su' }
- { src: '/bin/ls', dest: '/home/{{ limit_user }}/.bin/ls' }
- { src: '/bin/cat', dest: '/home/{{ limit_user }}/.bin/cat' }
- { src: '/bin/more', dest: '/home/{{ limit_user }}/.bin/more' }
- { src: '/bin/less', dest: '/home/{{ limit_user }}/.bin/less' }
- { src: '/usr/bin/vi', dest: '/home/{{ limit_user }}/.bin/vi' }
- { src: '/usr/bin/tail', dest: '/home/{{ limit_user }}/.bin/tail' }
- { src: '/bin/grep', dest: '/home/{{ limit_user }}/.bin/grep' }
- { src: '/usr/bin/top', dest: '/home/{{ limit_user }}/.bin/top' }
- { src: '/usr/bin/curl', dest: '/home/{{ limit_user }}/.bin/curl' }
- { src: '/usr/bin/stat', dest: '/home/{{ limit_user }}/.bin/stat' }
- { src: '/usr/bin/md5sum', dest: '/home/{{ limit_user }}/.bin/md5sum' }
- { src: '/bin/zcat', dest: '/home/{{ limit_user }}/.bin/zcat' }
- { src: '/bin/ps', dest: '/home/{{ limit_user }}/.bin/ps' }
- { src: '/usr/local/jdk/bin/jstack', dest: '/home/{{ limit_user }}/.bin/jstack' }
- { src: '/usr/local/jdk/bin/jstat', dest: '/home/{{ limit_user }}/.bin/jstat' }
- { src: '/sbin/ifconfig', dest: '/home/{{ limit_user }}/.bin/ifconfig' }
- name: 'copy .bash_profile to {{ limit_user }}'
synchronize:
src: '{{ item }}'
dest: /home/{{ limit_user }}
with_items:
- /data/control/init_hosts/limit_user/.bash_profile
- /data/control/init_hosts/limit_user/.bashrc
- name: 'modify {{ limit_user }} shell'
user:
name: '{{ limit_user }}'
shell: /bin/rbash
测试标签的 GIF: rbash 在 ubuntu 20.4 中无法使用 tab 键完成路径