Posts

Showing posts from May, 2020

How to create users for your EC2 Instance that can connect securely via ssh

Image
Public and Private Keys for AWS Users Create a normal user in AWS sudo adduser username How to add user in sudo group or wheel group sudo usermod --groups sudo --append username Allow user to run the sudo command without asking the password root ALL=(ALL) ALL username ALL=(ALL) NOPASSWD:ALL Or you can add complete sudo or wheel group. The users under sudo or wheel group run sudo command with asking password to sudo users %wheel ALL=(ALL) NOPASSWD:ALL %sudo ALL=(ALL) NOPASSWD:ALL To switch to the user directory cd /home/username Run the following command inside the user home directory to generate keys ssh-keygen - b 4096 -f username -t rsa To create the .ssh directory under user home directory mkdir .ssh Give permission to the owner to read, write and execute (700)  chmod 700 .ssh To store public key in authorized_keys file (after exit from the username   ) sudo cat username .pub >> .ssh/authorized_keys so that the owner can read and write to the file  chmod 600 .ssh/au

How to remove Let's Encrypt SSL Certificate from CentOS 7 - 8

Image
Please follow the steps to remove the Let's Encrypt SSL Certificate: First take a backup of letsencrypt directory under /etc - sudo cp -r /etc/letsencrypt/ /etc/letsencrypt.backup I deleted the ‘no longer needed domains’ in the three folders… rm -rf /etc/letsencrypt/live/${DOMAIN} rm -rf /etc/letsencrypt/renewal/${DOMAIN}.conf rm -rf /etc/letsencrypt/archive/${DOMAIN}

How to extend AWS EBS volumes with no downtime

Image
This can be applied whenever you need to extend your EBS volume size avoiding to stop the instance and detach the volume.  In order to extend the volume size, follow these simple steps:  Login to your AWS console  Choose “EC2” from the services list  Click on “Volumes” under ELASTIC BLOCK STORE menu (on the left)  Choose the volume that you want to resize, right click on “Modify Volume”  You’ll see an option window like this one: If your filesystem is an ext2, ext3, or ext4, type:  Set the new size for your EBS volume (in this case i extended an 8GB volume to 20GB)  Click on modify.  Now, we need to extend the partition itself.  SSH to the EC2 instance where the EBS we’ve just extended is attached to.  Type the following command to list our block devices:  lsblk You should be able to see a similar output: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 20G 0 disk └─xvda1 202:1 0 8G 0 part / As you can see size of the root volume reflects the new size, 20GB, the s

How to create Swap partition in CentOS 7? or MySQL frequently stopped

Image
Hello Friends, I am writing this post because one of my friend was facing the issue of MySQL or MariaDB service frequently stop every 2-3 days.  I have also faced this issue several time in the past. Hope this post will help you, if you are also facing the similar issue. First thing first, If you are using AWS and t2-micro free-tier or Digital Ocean smaller droplet or any least configuration machine. You need to upgrade your server also please keep eye on your disk space. As this post is all about to Add SWAP space and increase SWAP memory. Let's understand What is SWAP space or memory Swap space or memory is a space in the Hard Disk of your computer that Operating Systems will use to put the info that is actually on the RAM to free it for another application. This should be done when the system needs memory for a new process. Now come to the point. To Check available SWAP space sudo swapon -s         or sudo swapon --show There are two way to accomplish this - Creating SWAP Partit

How to install Python 3.6 on CentOS 7 (AWS, GCP)

Image
Hello Friends, Today, we are going to install Python 3.6 on RHEL Distribution (RHEL/CentOS) In AWS EC2 default Python comes with instance are 2.7.5. So here we will install Python version3.6.0. Step 1.  There are some Pre-Requisites for this, here we will resolve that one by one. Install the development, zlib-devel,openssl-devel sudo yum -y groupinstall development sudo yum -y install zlib-devel sudo yum -y install openssl-devel Install the PIP curl -O https://bootstrap.pypa.io/get-pip.py Use python to install pip python get-pip.py Step 2.  After installed all the Pre-Requisite, here we need to  install OpenSSL also to avoid the errors. Download the package OpenSSL_1_0_2l, extract, configure and finally clean unnecessary files and folder wget https://github.com/openssl/openssl/archive/OpenSSL_1_0_2l.tar.gz tar -zxvf OpenSSL_1_0_2l.tar.gz cd openssl-OpenSSL_1_0_2l/ ./config shared make sudo make install export LD_LIBRARY_PATH=/usr/local/ssl/lib/ cd .. rm OpenSSL_1_0_2l.tar.gz rm -rf ope

How to mount Amazon S3 Bucket into AWS EC2 instance

Image
Step 1 Update all the packages if required (RHEL/CentOS) yum update (Debian/Ubuntu) apt-get update Step 2 Install all the dependencies require to configure (RHEL/CentOS) sudo yum install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel (Debian/Ubuntu) sudo apt-get install automake autotools-dev fuse g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config Step 3 Clone the s3fs repository from the GitHub (RHEL Family and Debian Family) git clone https://github.com/s3fs-fuse/s3fs-fuse.git Step 4 Now change directory to just clone from the GitHub and compile and setup the s3fs-fuse cd s3fs-fuse ./autogen.sh ./configure --prefix=/usr --with-openssl make sudo make install Step 5 Run the following command to check if every set up correctly which s3fs Output /usr/bin/s3fs Step 6 Now, Go to IAM and create a user name "s3user" and give him Programmatic Access and attached the Policy "AmazonS3FullAccess". While creating

Monitor Memory and Disk Utilization on EC2 instances with Cloudwatch Custom metrics

Image
As you know, in AWS we cannot monitor Hard Disk (Volume) and Memory (RAM) through CloudWatch but with few steps, we can monitor and set alarm on it according to our needs. So, in this post we will see, how can we accomplish that. Step1. Installation of dependencies (packages and binaries) in order to setup Memory and Disk utilization RHEL 7 sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA --enablerepo="rhui-REGION-rhel-server-optional" -y sudo yum install zip unzip -y Amazon Linux 2 and Amazon Linux AMI sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64 -y  sudo yum install zip unzip -y SUSE Linux Enterprise Server sudo zypper install perl-Switch perl-DateTime sudo zypper install –y "perl(LWP::Protocol::https)" Debian Based Systems  sudo apt-get update sudo apt-get install unzip libwww-perl libdatetime-perl Step2. Download and configure the "Memory" and