Linux Scenario Based Questions

Linux Scenario Based Questions

  1. How would you create a directory named "Ritul" with a subdirectory named "Anjali" and a file named "hello.txt" inside the "Anjali" subdirectory using a single command in Linux?

     mkdir -p Ritul/Anjali && touch Ritul/Anjali/hello.txt
    
  2. You have a directory named "project" in your home directory, and you want to make sure that only you can read, write, and execute files within this directory. However, members of your group should be able to read and execute files, but not write. Other users should have no access to the directory.

     chmod 700 ~/project
     chmod 750 ~/project/*
    
  3. How do you manage users, permissions, and groups in Linux?

  4. Adding a New User

    • Scenario: You need to create a new user account named "john" on your Linux system with the home directory "/home/john" and the default shell as "/bin/bash".

    • Question: How would you add the user "john" to the system?

    sudo useradd -m -d /home/john -s /bin/bash john
  1. Modifying User Attributes

    • Scenario: The user "john" needs to change his default shell from "/bin/bash" to "/bin/zsh".

    • Question: How would you modify the shell for the user "john" without affecting other user attributes?

        sudo usermod -s /bin/zsh john
      
  2. Creating a New Group

    • Scenario: You want to create a new group named "developers" to manage access permissions for a specific project on your system.

    • Question: How would you create the group "developers" on your Linux system?

        sudo groupadd developers
      
  3. Adding a User to a Group

    • Scenario: You need to add the user "john" to the group "developers" to grant him access to project files.

    • Question: How would you add the user "john" to the "developers" group without affecting his other group memberships?

        sudo usermod -aG developers john
      
  4. Setting Group Ownership on a Directory

    • Scenario: You have a directory named "/var/www/html" that needs to be owned by the group "developers" for collaborative web development.

    • Question: How would you set the group ownership of the directory "/var/www/html" to the group "developers"?

        sudo chown :developers /var/www/html
      
  5. Setting User Expiry Date

    • Scenario: You have a temporary user account named "guest" that should expire automatically after one week.

    • Question: How would you set an expiry date for the user "guest" to deactivate the account after one week?

        sudo usermod -e $(date -d "+1 week" +%Y-%m-%d) guest
      
  6. Managing Secondary Group Memberships

    • Scenario: You want to list all users who are members of the "developers" group along with their other group memberships.

    • Question: How would you retrieve a list of users who are members of the "developers" group and their secondary group memberships?

        getent group developers | cut -d ':' -f 4 | tr ',' '\n' | sort | uniq
      
      1. System Resource Monitoring

        • Scenario: Your Linux server is experiencing performance issues, and you suspect that high CPU usage is the cause. You need to identify the processes consuming the most CPU resources.

        • Question: What commands would you use to monitor CPU usage and identify the top CPU-consuming processes?

            top
          
      2. Package Management

        • Scenario: You need to install the Apache web server on your Ubuntu Linux system. However, you want to ensure that it's installed along with all its dependencies.

        • Question: How would you use the APT package manager to install Apache and its dependencies in a single command?

            sudo apt-get install apache2
          
      3. Networking

        • Scenario: You need to troubleshoot network connectivity issues on a Linux server. You suspect there might be a problem with the server's network configuration.

        • Question: What commands and tools would you use to check the server's IP address, network interfaces, and network connectivity?

            1. Check IP Address: ip addr show
            2. Check Network Interfaces: ifconfig -a
            3. Check Network Connectivity: ping <destination>
          
      4. Filesystem Management

        • Scenario: You want to add a new hard drive to your Linux server and make it accessible to users. You need to format the disk with the ext4 filesystem and mount it to a specific directory.

        • Question: What commands would you use to partition, format, and mount the new disk?

            Partition the Disk: fdisk /dev/sdX
            Format the Partition: mkfs.ext4 /dev/sdX1
            Create a Mount Point: mkdir /mnt/newdisk
            Mount the Disk: mount /dev/sdX1 /mnt/newdisk
          
      5. System Backup

        • Scenario: You need to create a backup of critical system files and directories on your Linux server to an external drive.

        • Question: How would you create a compressed archive of the "/etc" directory and copy it to an external USB drive named "/media/backup"?

            sudo tar -czf /media/backup/etc_backup.tar.gz /etc
          
      6. Security

        • Scenario: You want to restrict SSH access to your Linux server to only allow connections from specific IP addresses.

        • Question: What configuration changes would you make to the SSH server to achieve this?

            1.Open the SSH server configuration file for editing: sudo nano /etc/ssh/sshd_config
            2. Find the line that starts with "AllowUsers" or "AllowGroups" or add the following line if it doesn't exist: AllowUsers <username>@<allowed_IP>
            3. Restart the SSH service to apply the changes: sudo systemctl restart sshd
          
      7. Log Management

        • Scenario: You are investigating a security incident on your Linux server and need to review the system logs for any suspicious activity.

        • Question: What commands or tools would you use to view and analyze the system logs stored in "/var/log"?

            View System Logs: cat /var/log/syslog
          
      8. If a particular server reaches 100% of the memory consumption or disk usage what will happen?

        If a server reaches 100% memory consumption or disk usage:

        • Memory consumption: This may lead to performance degradation, out-of-memory errors, and swapping.

        • Disk usage: This can cause filesystem errors, application failures, and service disruption.

      9. Difference between CPU consumption and memory consumption and what will happen if the CPU consumption goes to 100% and also on memory

        CPU consumption refers to the utilization of processing power by the CPU, while memory consumption is the utilization of system memory by running processes. If CPU consumption reaches 100%, the system may become unresponsive. If memory consumption reaches 100%, it can lead to performance degradation and potential system instability.

        Thank You!