May 23, 2023

Change default directory for Windows command prompt and Powershell when running with admin privileges

 Hi all,

It's been a while since I posted things.

Here is my previous post where the non-admin user changes the default directory for the command prompt and PowerShell.

https://psrdotcom.blogspot.com/2022/03/change-default-directory-of-windows.html

But in this post, I will be explaining about running the command prompt / powershell with admin rights and setting the default directory. Because, when you are running with admin privileges, it by default goes to the SYSTEM32 folder of Windows.

Environment

I use the command prompt and PowerShell, which are pinned to the taskbar of Windows.

Run the application with the admin rights

  • Right-click on the application icon -> click on Properties
  • Go to the "Compatibility" tab
  • Check "Run this program as administrator"

Run the shortcut with the admin rights

  • Right-click on the shortcut icon -> click on Properties
  • Go to the "Shortcut" tab
  • Click on the "Advanced" button
  • Check "Run this program as administrator"

Change the command prompt default directory

  • We need to have a .bat file with the following content
    • @echo off
    • cd <default_directory>
Now use the .bat file in the shortcut properties
  • Right-click on the shortcut icon -> click on Properties
  • Go to the "Shortcut" tab
  • In the "Target" field append the below text
    • /k "batfile_dirpath\batfile.bat"

Change the PowerShell default directory

  • Right-click on the shortcut icon -> click on Properties
  • Go to the "Shortcut" tab
  • In the "Target" field append the below context after powershell.exe
    • -NoExit -command "& {Set-Location <default_directory>}"
  • Click on "OK"

Hope, this helps you to reduce the frequent directory changes in the command prompt and PowerShell.

Feel free to provide your valuable feedback and comments to psrdotcom@gmail.com

June 11, 2022

Configure a API Backend Server with custom domain on Amazon Web Services (AWS) EC2 Ubuntu with NGINX and Certbot SSL

Hi all,

Build your own API backend server on AWS free-tier with SSL.

The below steps with reference links will provide detailed information of each step.

  1. AWS account - Free-tier
  2. Create EC2 Ubuntu
  3. Connect to Ubuntu from your local using SSH/Putty
  4. Install NodeJS
    1. Open terminal
    2. curl -fsSL http://deb.nodesource.com/setup_lts.x | sudo -E bash -
    3. sudo apt update
    4. sudo apt install nodejs //installs latest LTS nodejs
  5. Create a sample node server
  6. Install and configure node server process manager
    1. sudo npm install -g pm2@latest
    2. Navigate to nodejs server folder
    3. pm2 start <filename>
    4. pm2 startup systemd
    5. pm2 save
    6. pm2 list // List all the nodejs apps with status
    7. pm2 stop/restart/start app_name/id // Actions of nodejs servers
  7. Install Nginx
  8. Configure your domain DNS records to map to AWS EC2 public/elastic IP address
  9. Secure Nginx with SSL certs

Hope the above information is useful to set up the environment and play with your backend server.

Feel free to send your feedback and comments 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

April 29, 2022

Publish and Consume NPM Packages using GitHub Package Manager

 Hi folks,

We are used to publishing the npm packages on npmjs.com. Today, I will show how we can publish the npm packages to GitHub and the steps to use those packages.

1. Publishing Packages

Prerequisites

We need to have an account with GitHub

JavaScript native/framework based project with package.json

Add the .npmrc file to your project with the following syntax. Change the OWNER value to your GitHub account or organization name.

@OWNER:registry=https://npm.pkg.github.com

Publishing Process to GitHub

Create personal access token using the following steps

  • Login to GitHub
  • Go to Settings
  • Navigate to "Developer Settings" -> "personal access tokens"
  • Generate token with write:packages access permissions

  • Open terminal in the project folder
  • Execute the command to login
  • npm login --scope=@OWNER --registry=https://npm.pkg.github.com
  • When prompted,
    • Username: GitHub username
    • Password: Personal access token
    • Public e-mail: Your email address
  • Enter the following command to publish the package
  • npm publish

2. Consume/Installing the packages

Prerequisites

We need to have an account with GitHub

Installation

Add the .npmrc file to your project with the following syntax. Change the OWNER value to your GitHub author or organization name.

@OWNER:registry=https://npm.pkg.github.com

Enter the full name @OWNER/package-name-version in dependencies in package.json
Install the dependencies
npm install

Note: If the organization is asking for authorization of personal access token, then you need to authorize from the personal access token section against the token for the respective organization.

Hope you will make use of GitHub for publishing the packages and consuming them with ease.

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

March 14, 2022

Change default directory of Windows command prompt and Windows PowerShell

 Hi all,

Today I will explain the steps to change the default directory for Windows command prompt and Windows PowerShell.

The default directory for both the command prompt and PowerShell is the "system32" folder of the OS installed directory (By default: "C:\windows\system32").

Day in - Day out, we will open the terminals (command prompt / PowerShell) and navigate the source directory. It sometimes irritates and wastes lots of time.

I have come across this situation and want to avoid re-entry the change directory command.

Environment,

I use the command prompt and PowerShell, which are pinned to the taskbar of Windows.


Change default directory of Windows Command Prompt

  1. Right-click on the taskbar pinned Command Prompt icon
  2. Right-click on the "Command Prompt" menu
  3. Select the "Properties" item
  4. Under the "Shortcut" tab, you will find the "Start in:" label
  5. In the respective text box, enter the path you want to navigate by default.
  6. For example, "C:\Projects".

Change default directory of Windows PowerShell

  1. Open the PowerShell with administrator privileges
  2. Create a profile by using the following steps
    1. New-item -type file -force $Profile
  3. This will create a file "Microsoft.PowerShell_profile.ps1" in the current user documents PowerShell folder.
    1. Syntax
        • C:\Users\<UserName>\Documents\WindowsPowerShell
      1. Example
          • C:\Users\PSR\Documents\WindowsPowerShell
      2. Edit file
          • notepad.exe $Profile
        1. Change the default directory
          1. Syntax
              • Set-Location <Directory Path>
            1. Example
                • Set-Location C:\Projects
                  • Clear-Host # To clear the PowerShell screen
              1. Save and close the file
              2. In the PowerShell window, enter the following command to change the profile
                  • . $Profile
                1. It immediately changes from the current directory to the updated default directory.
                2. Close the PowerShell and try to open the PowerShell again to see the change in the directory.
                Hope the above information is helpful to you reduce the change directories in day-to-day life.

                Send me your valuable feedback to psrdotcom@gmail.com.

                March 10, 2022

                Git remove a specific commit(s) from history

                 Hi all,

                This blog post will let you know about the process of removing the git commit from git history.


                Sample Git log

                > git log 

                38384b3 initial commit

                f96751b UI changes

                2154131 file added

                bf9b9c1 Logic corrections

                3e75ab7 Bug fix -> (HEAD)


                Use case

                Remove the commit "file added"


                Procedure

                • Rebase in interaction mode one commit above which we want to remove.

                > git rebase -i f96751b

                • All the commits up to the specified commit will be listed in an order with the prefix "pick". Along with commit messages, the useful commands are available like below.

                pick = use commit

                reword = use commit, but edit the commit message

                edit = use commit, but stop for amending

                squash = use commit, but meld into previous commit

                fixup = like "squash", but discard this commit's log message

                exec = run command (the rest of the line) using shell

                drop = remove commit

                • Delete the unwanted commits from the file
                  • Press 'd' twice to delete line (in case of vi editor)
                • Save and quit the editor
                  • esc -> :wq (in case of vi editor)
                • If there are any merge conflicts, resolve it and perform rebase continue
                  • > git rebase --continue
                • Once all the merges are completed, perform the push operation
                  • > git push --force-with-lease origin
                Hope this helps you make sure, you have clean git history.

                Feel free to send your suggestions and comments to psrdotcom@gmail.com


                February 02, 2022

                Ubuntu - update NPM and NodeJS

                Hi folks,

                Some people often confuses with NPM update vs Node.js update.

                Let me clarify that, NPM (Node Package Manager) is a CLI (Command Line Interface) to manage the JS (JavaScript) packages from https://www.npmjs.com/ or any other external package managers like GitHub.

                Node.js is a FrontEnd JavaScript Framework like Vue.js, AngularJS which helps to build the scalable network applications. Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.

                NVM (Node Version Manager) and n are command line utilities to manage and switch between Node.js versions.

                When you are installed for the first time, you will be installing Node.js from https://nodejs.org/en/download/ which also installs NPM CLI utility.


                But when upgrading the NPM or Node.js, it's a different story.


                Update NPM

                npm install -g npm

                Update Node.js with Node version manager (n)

                Install the n

                sudo npm install -g n

                Update the Node.js to stable version

                sudo n stable

                As of now, the stable version is 16.3.2 which includes NPM 8.1.2

                Update the Node.js to current version

                sudo n current

                As of now, the current version is 17.4.0 with NPM 8.3.1


                Check the versions

                NPM

                npm --version

                Node.js

                node --version


                Hope this helps you to understand the NPM and Node.js difference along with update of individual components.

                Send your comments and feedback to psrdotcom@gmail.com

                 

                Featured Post

                Java Introdcution

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