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 »

Overview of SSH Tunneling and configuration options

This is the fifth post in the series of the blog posts about Secure Shell aka SSH. You can find the series index here. In this blog post, we’ll discuss about SSH tunneling and how to configure and use the same.

SSH port forwarding or SSH tunneling, is a mechanism in SSH for tunneling application ports from the client machine to the server machine or vice versa. It can be used for variety of purpose such as adding encryption to legacy applications, bypassing firewalls, opening backdoors into internal networks, etc. It is a double edged sword. It can be useful at the times but it can also be abused by hackers and malware to open access from the internet to the internal network.

Read More »

Customize SSH using Client side configuration options

This is the fourth blog post in the series of blog posts on the Secure Shell aka SSH. You can find the series index here. In the last post, we discussed how to customize SSH uing the server side configuration options. We discussed some of the most popular options and also shared location for list of full options available. In this blog post, we’ll discuss how we can customize the SSH session using some of the popular client side configuration options. Using these options can shape the way the connection is established and connection experience for the ssh clients.

Read More »

Customize SSH using server side configuration options

This is the third blog post in the series of blog posts on the Secure Shell aka SSH. You can find index here. In the last post, we discussed how to copy ssh public key to the remote server and then discussed few local options to create and customize ssh sessions. We also discussed about the usage of ssh-agent. In this blog post, we’ll discuss how we can customize the SSH session using some of the popular server side configuration options. Using these options can shape the way the connection is established and connection experience for the ssh clients.

Read More »