BashShellScriptInterviewQuestions
BashShellScriptInterviewQuestions
Automating the process of granting or revoking SSH access to a group of server instances for a new
developer can be streamlined using tools like Ansible, which is well-suited for managing
configurations across multiple servers. Below is an example approach to achieve this:
Prerequisites:
1. Ansible Installed: Make sure you have Ansible installed on your control machine.
2. SSH Access: Ensure that the control machine has SSH access to the servers where you need
to manage access.
3. Inventory File: Create an inventory file listing the group of servers.
4. Public SSH Key: You should have the new developer’s public SSH key.
[web_servers]
192.168.1.101
192.168.1.102
[db_servers]
192.168.1.201
192.168.1.202
This file lists all the servers where you want to manage SSH access. You can group them based on
roles like web_servers or db_servers.
---
- name: Grant SSH access to new developer
hosts: all
become: yes
vars:
developer_user: "new_developer"
developer_ssh_key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIw..."
tasks:
- name: Create developer user if not exists
user:
name: "{{ developer_user }}"
state: present
shell: /bin/bash
create_home: yes
---
- name: Revoke SSH access for developer
hosts: all
become: yes
vars:
developer_user: "new_developer"
developer_ssh_key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIw..."
tasks:
- name: Remove developer's SSH key
authorized_key:
user: "{{ developer_user }}"
key: "{{ developer_ssh_key }}"
state: absent
manage_dir: no