Get timestamps in Bash history

Although history command utility in Linux is already nice, it would have been great if we can have timestamp to understand when certain commands were run. This is particularly useful for organizations, that needs to match certain audit requirements. We can easily configure timestamps by using HISTTIMEFORMAT environmental variable in following way:

HISTTIMEFORMAT="%d/%m/%y %T "  # for e.g. "13/03/21 15:59:59"
HISTTIMEFORMAT="%F %T "        # for e.g. "2021-03-13 15:59:59"
Read More »

Solve your CIDR calculations without leaving terminal in Linux

Every system admin in this world has ran into problem of calculating IP address range, network masks, usable IP addresses, etc. for one or the other reason. It is very important part of networking related operations and what a server would be without any clients or IP addresses. Some people consider it so important, they expect you to do calculations like these in your mind in your job interviews. There are also various websites online to just run CIDR calculations. However its all additional steps and a hassle.

Fortunately, if you are a linux user, you can make life easy for yourself by using utility sipcalc. It is a simple command line tool which is available in epel repo.

Read More »

Convert JKS and P12 to Crt and Key files with OpenSSL

PKCS#12 is a successor to Microsoft’s PFX format. It defines an archive file format for storing many cryptography objects as a single file. It is commonly used to bundle a private key with its X509 certificate or to bundle all the members of a chain of trusted certificates, starting from the root certificate authority. The files PFX (.pfx) and PKCS#12 (.p12), including terms, are somewhat used interchangeably and refer to same standard.

PKCS#12 are normally generated using OpenSSL, which is an open-source tool. We can use the same tool to convert JKS, which is Java keystore and PKCS#12 certs to crt and key files.

Read More »

Debug Bash Shell Scripts in Linux

Debugging code can be time consuming and tricky at times. Programmers have traditionally taken advantage of the techniques like syntax highlighting, code completion, intellisense, etc while writing and debugging code. Also no amount of such features can reduce logic based errors, where the script executes but not in a way we expected. This is more problematic with complex bash scripts as bash itself has no support for advanced features like these and most of the sysadmins spend their time with the editors like vi/nano/atom. Sometimes, even simple mistakes like missing a space, can make your scripts fail to run. In this blog post, we’ll discuss some of the common ways to debug bash shell scripts.

Read More »

Testing Bash Script Syntax Before Running

The terminal based editors for bash scripts do not usually point out any errors in bash script syntax. You can often make mistakes when creating a complicated syntax or editing long scripts. It would be good to have bash script checked for syntax before running it or before checking into source control management systems, so as to prevent any last minute issues.

For this issue, we can use bash -n syntax. Let’s see what happens if we run this on a well structured script:

Read More »

Change default Login Shell to PowerShell on Linux

With PowerShell 7, PowerShell Core has been improved and resolved the issues with environmental variables in the *-nix based operating systems. If you have been working with Linux Servers and are using PowerShell to perform some kind of administrative tasks, you may also want to set it as default login shell for certain users. This makes it easy to invoke certain scripts since a familiar shell is available when you are calling the environment.

There are many ways to change the shell like using usermod or chsh or may be if you are feeling adventurous, by modifying /etc/passwd directly using vi editor. So let’s get started.

Read More »

Enable PowerShell Remoting on Linux using OpenSSH

Linux has always been an important part of the server infrastructure world and SSH has been the primary method of connecting to it. PowerShell can now use same underlying SSH Protocol to perform SSH and manage Linux servers centrally. This functionality allows us to seamlessly incorporate Unix servers using the known PSRemoting commands into the PowerShell scripts. PowerShell based SSH remoting creates a PowerShell host process on the target computer as an SSH subsystem. In this blog post, we’ll learn how we can enable and use the same on one of the popular Linux distributions, Ubuntu. The same set of steps can be used for other Linux distributions as well.

Read More »

SSH basics and configuration – Index

This post is to act as the index for the series of blog posts written on SSH. In the series, we discussed on what is SSH, how it works, different configuration options and few advanced features such as SSH tunneling. It can be used to get a quick overview of and navigate to find the related post of interest.

Part 01 – Basics of SSH, How it works, Various authentication methods, Generate SSH Key pairs

Read More »