Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

November 06, 2025

Migrate from Nginx to Caddy for SSL auto-renewal in Amazon AWS EC2

 Dear friends,

Today, we will see a simple migration with less configuration of SSL auto-renewal.

I was using Nginx for SSL auto-renewal using certbot. Every 90 days, the renewal code should run, I made one more service it.

I have come across Caddy, which does an auto-renewal of SSL automatically with certbot. Reducing efforts and making the system smooth.

Follow the steps below

Stop and disable the Nginx

sudo systemctl stop nginx

sudo systemctl disable nginx

Install the Caddy

In EC2, if you are running Amazon Linux, then execute the following to install Caddy.

    sudo yum -y install yum-plugin-copr

    sudo yum -y copr enable @caddy/caddy epel-8-$(arch)

    sudo yum -y install caddy

Edit and configure the Caddyfile

Usually, it will be in the path /etc/caddy/Caddyfile

sudo vi /etc/caddy/Caddyfile

I have only one server that is running locally. So, my configuration is easy

domain_name {

    reverse_proxy localhost:port

}

You can configure more with your existing Nginx sites-enabled reference.

Happy SSLing.

If you like the blog or want to comment, kindly reach out to psrdotcom@gmail.com


June 09, 2022

Generate Free SSL HTTPS Certificates with 90 days validity using letsencrypt

 Hi all,

As discussed in my earlier blog, Generate Free SSL Certificate using ZeroSSL where the limitation of one free certificate on ZeroSSL can be eliminated using Get HTTPS for free!

This process includes the following prerequisites and procedures.

Note: This process is not for beginners or production usage scenarios. Use this process if you are knowledgeable about certificate generation.

Prerequisites

  • OpenSSL command line
  • [Li]nix / Mac OS

Procedure

  • Open the URL https://gethttpsforfree.com
  • It has 5 steps
    • Account Info
    • Certificate Signing Request
    • Sign API Requests
    • Verify Ownership
    • Install Certificate
  • In each step, some commands or processes need to be followed to get the free SSL certificate.

  1. Account Info
    1. In this step, we will be providing the email and public key.
    2. Keep the generated private key security in your system.
      • Note: If you are unsure about the public key generation commands, click on the "how do I generate this?" link, which is available over the public key input textbox.
  2. Certificate Signing Request (CSR)
    1. Generate the CSR for the required domains
      • Note: You can generate the CSR for wildcard certificates and www subdomain with the same command
    2. Try to follow the same format, including the line feeds mentioned below.
    3. #change "/etc/ssl/openssl.cnf" as needed:
          #  Debian: /etc/ssl/openssl.cnf
          #  RHEL and CentOS: /etc/pki/tls/openssl.cnf
          #  Mac OSX: /System/Library/OpenSSL/openssl.cnf
      
          openssl req -new -sha256 -key domain.key -subj "/" \
            -reqexts SAN -config <(cat /etc/ssl/openssl.cnf \
            <(printf "\n[SAN]\nsubjectAltName=DNS:foo.com,DNS:www.foo.com")) 
  3.  Sign API Requests
    1. Sign all the requests with the private key
    • Note: You need to copy the command and execute it on your PC/Mac terminal, and the result needs to be pasted on the web page.
  4. Verify Ownership
    1. In this step, you need to prove your domain ownership
    2. You will be given 3 options
      1. Python server
      2. file-based
      3. DNS record (I've used this option)
        1. Update the DNS records with new TXT entries, and use the online dig tool to make sure the records are visible.
        2. After we verify the availability of the records, you need to click on the respective buttons on the web page.
    3. Repeat the same steps for each domain on CSR (www and any sub-domains).
  5. Install Certificate
    1. You will be able to receive your certificate in "chained.pem" format
    2. Copy and paste the first certificate section (e.g. the first "-----BEGIN CERTIFICATE-----" section) into a text file named "domain.crt".
    3. Copy and paste the second certificate section (e.g. the second "-----BEGIN CERTIFICATE-----" section) into a text file named "intermediate.pem".
    • Note: Expand the "how do I install this?" link for quick help.
Hope this will help you to generate free SSL for your websites.

Request you to send your valuable feedback and comments to psrdotcom@gmail.com

October 06, 2020

Convert JSON file to CSV with Python

 Hi folks,

Today I will explain the code to implement the Json2CSV conversion.

Make sure you have valid JSON file with an array of objects.

Sample:

"Users":[

{"id": 1, "Name": "Suresh Raju", "Age": 35},

{"id":2, "Name": "PSR", "Age": 34}

]

I have chosen Python language to convert because of inbuilt library support for json and csv and command line execution with Notepad++ as editor.

Source Code Snippet: GitHub Gist

Please send your valuable feedback and comments to psrdotcom@gmail.com


June 24, 2020

Connect or Mount USB Storage drives in Windows Linux Sub System

Hi folks,

This post will explain the process of connecting / mounting USB devices to Windows Linux Sub Systems

Mount removable media (e.g. E:)

$ sudo mkdir /mnt/e
$ sudo mount -t drvfs E: /mnt/e

Unmount

$ sudo umount /mnt/e
Send your comments and feedback to psrdotcom@gmail.com


November 21, 2018

Connect to remote Oracle database server from RedHat Linux 7 using Oracle InstaClient

Hi friends,

I have come across a situation, where I need to connect to remote Oracle database server from RedHat Enterprise Linux (RHEL) 7. I found a way of using the Oracle InstaClient instead of installing the full Oracle DB which internally consists of Client.

Pre-requesites


  1. Linux mahcine (I tried with RHEL 7) with following softwares
    • Java (JAVA_HOME should be available)
    • Development Tools (RHEL 7 tools like gcc etc.)
  2. Another machine where Oracle server is installed with the following config
    • Database schema should be available
    • Users should be available instead of system/sysdba users
  3. Both machines shall be reachable to each other via ping.

Note: You should know the database server SID/service name.

Procedure

Download


  1. Download the insta client from Oracle Official Page
  2. In my case, I have downloaded the "Instant Client for Linux x86-64"
  3. Accept the license agreement
  4. Click "oracle-instantclient18.3-basic-18.3.0.0.0-1.x86_64.rpm" to download
  5. Optionally, you can download the "oracle-instantclient18.3-sqlplus-18.3.0.0.0-1.x86_64.rpm" to have sqlplus command line utility for testing
  6. Alternatively, you can download the zip files and download the same to install.
  7. In my case, I am going with RPMs.

Install


  • Install the downloaded RPMs
    • #> yum install oracle-instantclient18.3-basic-18.3.0.0.0-1.x86_64.rpm
    • #> yum install oracle-instantclient18.3-sqlplus-18.3.0.0.0-1.x86_64.rpm
  • While installing, it asks for locations, accept the defaults by pressing the "Enter" button

Note: If any dependencies are there, please install those.

Environment Variables


  • Create a oracle_env.sh file and setup your variables
    • #> gedit /etc/profile.d/oracle_env.sh
    export ORACLE_HOME=/usr/lib/oracle//client/
    export TNS_ADMIN=/usr/lib/oracle//client/
    export PATH=$ORACLE_HOME/bin:$PATH
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH



    • Save your file
    • Source your file with following command
      • #> source /etc/profile.d/oracle_env.sh

    tnsnames.ora


    • Create tnsnames.ora file in your $ORACLE_HOME with following syntax

    localsid = (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = ))
        (CONNECT_DATA =
          (SID = )
        )
      )

    • Instead of SID, you can use SERVICE_NAME also.

    Connect


    • You can test the connection
      • #> sqlplus @


    You should be able to connect to your remote database.

    Hope, it is useful for you.

    Please send your comments and feedback to psrdotcom@gmail.com

    November 20, 2018

    Completely uninstall openjdk in RedHat Enterprise Linux (RHEL)

    Hi all,

    Today, I'll explain how to uninstall completely the openjdk from the RedHat Enterprise Linux (RHEL) machine.

    Some of the softwares requires only the Oracle Java and having the openjdk, sometimes causes an issue. So, some users wants to remove the openjdk from the linux machine.

    Pre-requisites


    • openjdk installed on the machine
    • Check for java alternatives, when multiple java versions installed
    • #> /usr/sbin/alternatives --config java
    • Result with + is the currently selected java for the machine


    Procedure


    1. Find out the installed openjdk versions

    #> rpm -qa | grep java
    #> rpm -qa | grep jdk

    Sample Output:

    java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
    java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6.x86_64


    2. Remove the all openjdk versions

    #> yum remove <>

    Example:
    #> yum remove java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
    #> yum remove java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6.x86_64

    Hope, it is useful for you to configure java on your linux machine.

    Please send your feedback and comments to psrdotcom@gmail.com

    January 20, 2017

    Change EOL (End Of Line) Character from Windows to Unix/Linux for all the files in current working directory

    Hi all,

    For a single file, you can do the change of EOL using notepad++.
    Reference: http://psrdotcom.blogspot.in/2017/01/change-eol-end-of-line-character-from.html

    But it would be difficult, if you want to do for multiple files in one go.

    I have found a solution to update EOL for all files in the current directory.

    Pre-requisite

    Make sure that, working directory contains only the files which you want to change EOL.

    Note: If not, copy the files to a new directory and change the EOL for all the files in that directory.

    Procedure

    1. Download dos2unix utility from sourceforge https://sourceforge.net/projects/dos2unix/
    2. Extract the zip file
    3. Tip: Make sure that the extracted path doesn't contain spaces.
    4. Keep the bin directory available in your PATH environment variables
    5. Download the customized batch file from GIST https://gist.github.com/psrdotcom/d73ff9590c3010253b5b2a886704b26b
    6. Extract if needed, and place the "dos2unixfolder.bat" in the same directory where the "dos2unix" is placed.
    7. Tip: If you place the batch file in the same folder of dos2unix.exe. You no need to add again the patch of batch file in environment PATH.
    8. Navigate to your folder, where you want all the files EOL to be changed
    9. Press "Right Click on Mouse" in empty area
    10. Select "Open Command Prompt Here"
    11. Type the batch file name "dos2unixfolder.bat"
    12. You will able to see the conversion process
    13. Once the conversion is completed, you can check the EOL coversion in notepad++.
    14. If you need to help in checking, refer to http://psrdotcom.blogspot.in/2017/01/change-eol-end-of-line-character-from.html


    Please send your comments and feedback to psrdotcom@gmail.com

    Change EOL (End Of Line) Character from Windows to Unix/Linux using Notepad++

    Hi all,

    Today I will explain about updating/converting EOL for a single file from windows format to unix/linux format.

    1. In Windows, the EOL (End-Of-Line) character is \r\n (CR LF) (Carriage Return, Line Feed)
    2. In Unix/Linux, the EOL character is \n (LF) (Line Feed)

    Check for EOL

    If you open the file in notepad++, you will be able to see the EOL character by following below steps:


    • Type the content and hit enter button on keyboard
    • Choose menu "View -> Show Symbol"
    • Check the "Show End of Line" option

    • Now, you will be able to view "CR LF" special symbols in you file at every line end as show below

    Update EOL

    To convert the EOL from Windows (CR LF) to Unix (LF), do the following

    • Click on "Edit" menu
    • Choose "EOL Conversion"
    • Select "Unix(LF)"

    • Now, you can check the update EOL character in your file. Example conversion show below

    This type of conversion useful, when you are updating file in windows and using the same file in U/Linux environment.

    Batch File Update

    For all files in one folder, you can follow my blog.
    Reference: http://psrdotcom.blogspot.in/2017/01/change-eol-end-of-line-character-from_20.html

    Send your comments and feedback to psrdotcom@gmail.com

    November 27, 2015

    Creating Symbolic Link (Symlink) in Windows 7

    Hi friends,

    In Linux, it is easy to create symbolic link (symlink) with "ln" command.
    But what about in windows?

    I found one GUI and command for creating the symbolic links in windows.

    Pre-requisites

    1. Visual Studio 2005 redistributable
    2. Link Shell Extension
    3. Download the above executables from here based on OS and system architecture
    4. For Windows 7 64-bit, I have downloaded the following highlighted in black box

    Procedure

    • Install the Visual Studio 2005 redistributable
    • Install Link Shell Extension
    • You should be able to see an option in context menu
    • Select the file/folder
    • Right click and select the option "Pick Link Source"

    • Now, the file is been picked
    • Navigate to go the destination folder where you want to create the symbolic link
    • Right click on the empty space of the folder
    • Select Drop As and select "Hardlink or Symbolic Link" based on your requirement


    • You should be able to see the file type as .symlink


    References

    http://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/

    Please send your feedback and comments to psrdotcom@gmail.com

    July 18, 2012

    Text Formatting in *NIX to run Script files of Different Platforms

    Hello all,

    While writing shell scripting in Ubuntu, Windows and deploying it in *NIX based machine, we found some issue. That the file running perfectly on the Ubuntu (Linux), Windows machine. The same script was displaying errors like

    '\r': command not found
    ^M: command not found
     
    There was a formatting issue. You need to run the following command to resolve it.

    DOS2UNIX

    Installation:
    sudo apt-get install tofrodos

    Syntax: 
    dos2unix filename

    Example:
    dos2unix script1.sh

    To know more about this you can go through References.

    References:
    http://linuxcommand.org/man_pages/dos2unix1.html
    http://www.thefreecountry.com/tofrodos/

    If you have any further queries, please add your comments. You can also mail to psrdotcom@gmail.com

    June 07, 2012

    Ubuntu Linux Free and Best Audio (MP3, Ogg, etc.) and Video (AVI, MP4, etc.) Editors, Cutter, Joiner

    Hi folks,

    I would like share some best audio and video editors in Ubuntu Linux. Install common-codecs to use these Audio/Video editors.

    In Ubuntu Software Center, search for Ubuntu restricted extras and install.

    Audio Editors:
    • Audacity
    • Command Tools for MP3 Cutter and Joiner: mp3split, mp3wrap
    • Jokosher
    • Grip
    • Hydrogen
    • Sound Converter (Extract Audio from a Video File)
    • Muse
    • RoseGarden
    • Ardour
    • SoundKonverter
    • StreamRipper
    • LLMS

    Video Editors:
    • Openshot
    • AvideMux
    • Cinelerra
    • Kino
    • Jahshakha
    • Pitvi
    • Lives
    • Vivia
    • FFMpeg
    • Handbreak
    • VLC Media Player (Don't get surprise, see the 4th Reference link)

    Most of the above mentioned softwares can be downloaded from the Ubuntu Software Center/Synaptic Package Manager.

    Download the editor(s) and, be creative in your own way.

    References:

    http://ubuntup.blogspot.in/2010/09/best-audio-mp3-cutter-converter-editor.html
    http://techcityinc.com/2009/04/14/10-best-audio-editors-for-linux/
    http://techcityinc.com/2009/02/04/top-10-free-video-editors-for-ubuntu-linux/
    http://ubuntup.blogspot.in/2010/10/best-video-editor-converter-splitter.html

    April 26, 2012

    Shelr.tv, Record your Terminal / Console and Share Online

    Hi friends,

    If you want to share your terminal work with your friends/official/public.

    About Shelr.tv: http://shelr.tv/about

    I have uploaded a sample terminal work of mine. Just listing .txt file(s)



    Click on the Play button to view the recorded work.

    We can create and share online tutorials and lot more by using this. If you are interested to do so, please follow the below procedure to install and record using shelr.tv


    Pre-Requisites:

    1. Any Linux OS, Mac OS X
    2. Ruby and Rubygems


    Your Identity:

    • Register with Shelr.tv to create an account with your any one of the existing ID (GitHub, Twitter, Google, OpenID)
    • You will be getting your unique ID from Shelr.tv
    • Now you are ready to record your terminal work


    Installation:

    I have tried with Ubuntu 11.10.

    Please see the installation process here.

    As you can see the bold faced lines are the commands which has been executed.

    user@user-Vostro-230:~$ sudo add-apt-repository ppa:gwibber-daily/ppa
    You are about to add the following PPA to your system:
     PPA for gwibber-daily
     Daily builds of Gwibber trunk
    Press [ENTER] to continue or ctrl-c to cancel adding it

    Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.aTSMFL4Xlg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80/ --recv 06D1ED00EB802A66640696C8D0AFF96872D340A3
    gpg: requesting key 72D340A3 from hkp server keyserver.ubuntu.com
    gpg: key 72D340A3: public key "Launchpad PPA for gwibber-daily" imported
    gpg: Total number processed: 1
    gpg:               imported: 1  (RSA: 1)

    user@user-Vostro-230:~$ sudo apt-get update
    Reading package lists... Done
    W: GPG error: http://ppa.launchpad.net oneiric Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 588CD9FC28446D73

    user@user-Vostro-230:~$ sudo gem install shelr
    Fetching: json-1.6.6.gem (100%)
    Building native extensions.  This could take a while...
    Fetching: shelr-0.15.1.gem (100%)
    Successfully installed json-1.6.6
    Successfully installed shelr-0.15.1
    2 gems installed
    Installing ri documentation for json-1.6.6...
    Installing ri documentation for shelr-0.15.1...
    Installing RDoc documentation for json-1.6.6...
    Installing RDoc documentation for shelr-0.15.1...


    Record:

    1. Setup the Shelr with your unique id
    2. Run the record command
    3. Play the recorded work
    4. Push the recorded work
      • You will be prompted with "Description" and "Tags" of the work
      • Once successfully published the work, you will get the link (URL) of published one


    Please see the sample recording and publishing of work.

    user@user-Vostro-230:~$ shelr setup 8333xxxxxxxxxxxxxxxxxx

    user@user-Vostro-230:~$ shelr record
    Provide some title for your record: PSR's First Shelr Record
    /home/user/.local/share/shelr/1335339141/meta
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    => Your session started
    => Please, do not resize your terminal while recording
    => Press Ctrl+D or 'exit' to finish recording
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Script started, file is /home/user/.local/share/shelr/1335339141/typescript
    user@user-Vostro-230:~$ ls -l *.txt
    -rwxr-xr-x 1 user user 64 2011-05-12 15:52 mozilla.txt
    user@user-Vostro-230:~$ exit
    Script done, file is /home/user/.local/share/shelr/1335339141/typescript
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    => Session finished

    Replay  : shelr play last
    Publish : shelr push last
    user@user-Vostro-230:~$ shelr play last
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    user@user-Vostro-230:~$ ls -l *.txt
    -rwxr-xr-x 1 user user 64 2011-05-12 15:52 mozilla.txt
    user@user-Vostro-230:~$ exit
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    user@user-Vostro-230:~$ shelr push last

    Your record will be published under terms of
    Creative Commons Attribution-ShareAlike 3.0 Unported

    Description: PSR's First Recording using Shelr.tv
    Tags (ex: howto, linux): Test, Shelr, Ubuntu, PSR
    => Record published!
    user@user-Vostro-230:~$ 

    For further queries, please mail to psrdotcom@gmail.com

    Featured Post

    Java Introdcution

    Please send your review and feedback to psrdotcom@gmail.com