Skip to main content

Posts

Linux Daily Uses & Advance Commands – Part 2

  11. How to lock and unlock the user account? passwd -l (lock user account) passwd -u (unlock user account) 12. What is the command to view and change the expiry date for any user? chage -l username chage -E YYYY-MM-DD username 13. What are the field of /etc/passwd file?  7 filelds test:x:1000:1000:test:/home/test:/bin/bash (grep test /etc/passwd) username:password(encrypted stored in  etc/shadow):UID:GID:description:user-home-directory:default-login-shell 14. What is the difference between .bash_profile and .bashrc? Ans. When you log on the system .bash_profile is executed but if you already logged in or open any new terminal .bashrc is executed. 15. What are the details you get the finger command? Ans. It is not pre-install with OS, we are to install finger. It give the login and shell information of a user. 16. Name 3 files which automatically created inside any user’s home directory when a user is added? Ans. . bashrc   .bash_profile  Bash_history  ...

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...

How to SSH EC2 instance with ssh-agent along with SSH agent forwarding to SSH private instances in VPC?

            Image Source: atulhost.com and modified by me        Hi, I have taken this post from AWS Blog, and this very important to SSH into your VM using ssh-agent and SSH forwarding for EC2 private instance to SSH without storing the private key securely in Windows, Mac, and Linux.  So, I want you to using this as this is very important as per security reasons. Configuring ssh-agent The first step in using SSH agent forwarding with EC2 instances is to configure a bastion in your VPC. We suggest that the instance you use for your bastion be purpose-built and that you use it only as a bastion and not for anything else. The bastion should also be set up with a security group that’s configured to listen only on the SSH port (TCP/22).  Always remember the following when configuring your bastion: Never place your SSH private keys on the bastion instance. Instead, use SSH agent forwarding to connect first to the bastion and from t...

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...

Google Cloud Storage Command-line Utility [GSUTIL]

GSUTIL Command-line utility for Google Cloud Storage Create Bucket (Including Storage Class, Location) gsutil mb -c [storage class] -l [location] gs://bucket-name Remove Bucket  gsutil rm -r gs://bucket-name Parallel multi-threading copy  gsutil -m cp -r . gs://bucket-name Turn on versioning on bucket (get details of versioning enable or not)  gsutil versioning get gs://bucket-name Set versioning off gsutil versioning set off gs://bucket-name Enable the versioning gsutil versioning set on gs://bucket-name List all version of a file gsutil ls -a gs://bucket-name Long listing format generation and meta-generation gsutil ls -al gs://bucket-name Changes the storage class of a object in a bucket  gsutil rewrite -s NEARLINE gs://bucket-name/* Change the storage class of multiple objects (Multi-Threading Parallel)  gsutil -m rewrite -s NEARLINE gs://bucket-name/* Access Control List (ACL) on objects (Public access to the general public) gsutil acl ch -u AllUsers:R gs:...

How to transfer Google Cloud Storage One account data to Google Cloud another account?

                                                          Image Source: infiflex.com Step 1: Go to the account where storage bucket are resides. Select the Select the Bucket, you want to transfer data and Click on SHOW INFO PANEL on the Top Right. Step 2: Under PERMISSIONS click on Add members. Now type the email id of the another account where you want to transfer all of your files in New Members Box. Select Role Storage > Storage Admin. Step 3: Now, Go to second account, Go to your storage bucket and select and repeat the last steps but this time email id will be the 1st account email id. All Set. Step 4: Finally Go to First account open the Google Cloud Shell and run the following command - gsutil -m cp -r gs://SOURCE-BUCKET-NAME /* gs://DESTINATION-BUCKET-NAME /

Setup and Configure AWS CLI on EC2 Instances

For Linux Systems Prerequisites:  You must ensure that you have at least Python 2 version 2.6.5+ or Python 3 version 3.3+ installed. To verify your current version, run the command: python --version Installation: The recommendation for installing the AWS CLI is to use the bundled installer provided by AWS. The bundled installer includes all dependencies required for the installation.  Step 1. To begin the installation run the following command: sudo curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip" Step 2. Next, you must unzip the downloaded package from step 1: sudo unzip awscli-bundle.zip Step 3. Once the package in unzipped, you can run the installation: sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws Using the -b option allows all users to use the AWS CLI from any directory, meaning you will not need to specify the install directory in the user’s $PATH variable.  Step 4. Check the installed version /usr/local/b...