Skip to main content

Linux Daily Uses & Advance Commands – Part 1

 





1. How to remove files older than 7 days by creating a cron job to run every night?
find /var/log/security -type f -mtime +7 -exec rm -rf {} \;
Cron – /etc/crontab (show the cron format)


To add the command in crontab file
crontab -e
0 0 * * * /bin/find /var/log/security -type f -mtime +7 -exec rm -rf {} \;


2. Run a command that shows all the line except any lines starting with a character # in the file?
    cat filename | grep -v ^#  (character name you want to omit)


    3. Which 2 files contain default values when creating a user with useradd command? 


    First File: /etc/default/useradd

    Second File: /etc/login.defs
    cat /etc/default/useradd

    grep -v ^# /etc/login.defs | grep -v ^$ [first # symbol for omit and second $ for omit space)
    Password max, min, warn days | password length | UID and GID min, max | umask | encryption method



    4. What is the command to create user with a pre defined uid, shell and home directory?
      useradd -m -d /home/username -s /bin/bash -u 9000 username
      grep username /etc/passwd


      5. How to delete a user with his home directory?

      userdel -r username


      6. How to create a user specifying a primary/secondary group?
      useradd -g test -G wheel username [small g for primary group and capital G for secondary group)
      id username [to check user information]


      7. How to change primary group of any user?
        usermod -g primarygroupname username


        8. How can you give a normal user all the root level privileges? 

        The file path is /etc/sudoers (But we never change the sudoer file directly, we edit the file with visudo command)
        visudo
        Change the file line # # Allow root to run any command anywhere
        root  ALL=(ALL) ALL
        gautam ALL=(ALL) ALL (Add this line below the root line)


        9. How can you give sudo access to any user without asking him to provide password every time he runs a command?
        visudo
        Add the line below – # # Same thing without a password [we need to add user in wheel group)

        # %wheel ALL(ALL) NOPASSWD: ALL
        linux ALL(ALL) NOPASSWD: ALL


        10. How to view the user’s login and logout details?
          last 
          last username (particular user detail)

          Popular posts from this blog

          WordPress Site is not loading properly behind Google Cloud/AWS Load Balancer

          Hello Guys, Today we are going to understand how can we fix a WordPress loading issue (CSS and JS loading issue) behind the Google Cloud Load Balancer or AWS Load Balancer. Generally, When we host a WordPress site directly with Google Cloud Compute Engine VM instance or AWS EC2 instance. It's loading perfectly fine. But once we added this WordPress server behind any Load Balancer either from GCP Load Balancer or AWS Load Balancer, you site will completely broken, means the CSS and JS of your site not loaded properly. The reason for this is - When you put a load balancer in front of WordPress, you need to modify wp-config.php to process the HTTP header HTTP_X_FORWARDED_PROTO to detect the protocol that the user is using and not the protocol the load balancer is using to connect to your backend. To fix this issue, we have to make following changes in the  wp-config.php  file and add the below code snippet on the top of  wp-config.php file - Google Cloud Platform Load Bal...

          How to Setup Kubernetes Cluster in Google Cloud Virtual Machine using "kubeadm"? | Ubuntu 20.04/22.04 LTS

            Hello Friends, In this post, we are going to setup Kubernetes Cluster on Virtual Machine in Google Cloud Platform using kubeadm tool. Hope this post will help you in Kubernetes learning Hand-On Labs (HOL). Requirements: Master Node: No. of VMs 1 Specifications - 2 vCPUs, 4GB RAM, 20 GB HDD (Balanced PD or SSD PD), Operating System (OS) Ubuntu 20.04 LTS x86/64, amd64  Firewall Rule - Ingress Allow 6443 (API Server) | 2379 (ETCD) | 10251 (Scheduler) | 10252 (Controller Manager) 10250 (Kubelet), sudo access with admin access  Worker Node: No. of VMs 2 Specifications - 2 vCPUs, 4GB RAM, 20 GB HDD (Balanced PD or SSD PD), Operating System (OS) Ubuntu 20.04 LTS x86/64, amd64  Firewall Rule - Ingress Allow 30000-32767 (Services) | 10250 (Kubelet),  sudo access with admin access  Disable Swap and comment fstab entry: First, Disable Swap and remove or comment the Swap entries from fstab file : sudo swapoff -a sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab Next...

          How to Convert PEM KeyFile into PPK KeyFile and vice versa?

          Hi, In this post, we will learn that how can we convert PEM KeyFile into PPK KeyFile and vice versa including the installation of the tool which we will use to accomplish this. For the Windows Operating System In Windows system is easy and straight forward. You just need a tool called "puttygen.exe" from the URL -  https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html Choose the appropriate version as per your OS. Convert PEM into PPK in Windows After downloading the PuTTYgen and open it, load your file (select All Files (*.*) in the bottom dropdown to select your PEM key file).  You will get a message Successfully imported foreign key, Just click OK, Now click on Save private key button to save that key in the location where do you want to save it. Convert PPK into PEM in Windows Now we will convert PPK file into PEM using PuTTYgen in Windows PC Open the PuTTYgen tool, now load your PPK file into it, and finally, Go to Conversions Menu and Click on Export OpenSSH k...