Bash Is Not A Shell Game
Originally published: IT Jungle on 9/17/14
Updated author notes:There are new ways to set the default PASE shell on IBM i.
It is interesting to observe where the IBM i side of IBM invest their resources. The operating system and database get a whole lot of investment but the native application layer seemingly not nearly as much. Why? Because I don’t believe they see a viable future for modern applications being written in timely fashion with the likes of RPG. If that were true then what future does the platform have? The PASE environment on IBM i is the remaining hope for the operating system to live in the realm of modernity. Why? Because that’s where modern things are being ported to run. First we had commercially supported Java, then PHP, and now Ruby – they all run in PASE. This article will give an introduction for how to work with PASE from what’s called an SSH session so you can begin to be made comfortable with this different approach in interacting with the IBM i server.
First let’s do some high level definitions of terms covered in this article:
PASE – An AIX integrated runtime environment on IBM i and is where Ruby runs. It does not include the AIX kernel and instead the IBM i kernel is called upon.
SSH – A cryptographic protocol used to securely communicate from your laptop to a shell session on IBM i.
Shell – A “shell” is a text-based interface that reads typed commands, runs them, and returns the output. Shell sessions are facilitated by IBM i jobs which you can view from
WRKACTJOB. There are many different types of shells, each with its own flavors and utilities. Here we will be talking about what’s called the “bash” shell.
Bash – An implementation of a shell based on the original Bourne shell (sh). Bash stands for “Bourne-again shell”.
The IBM i ships with the Korn, Bourne, and C shells which can be started by typing
CALL QP2TERM from a 5250 terminal. If you’ve ever used the terminal capabilities of Linux or Mac OSX you will soon realize using the aforementioned shells through a 5250 telnet session is cumbersome at best. Instead it is preferable to use an SSH client from your laptop to a bash shell on IBM i because of additional features – tab-completion, command history with up/down arrows, and the ability to use server-side editors like joe.
Starting SSH Daemon
Before you can login with SSH you need to make sure the SSH daemon service is running. Issue the following command to start it and if it is already running then a simple diagnostic message will be displayed back to you.
The SSH daemon job runs in subsystem QUSRWRK, as shown below.
You can now log in from your laptop with an SSH client. If your laptop is running Mac or Linux then you already have SSH client capabilities available through pre-installed applications (i.e. Terminal on Mac). If you are on Windows you will need to download a tool like Putty (free), as shown below. In the below screenshot the ‘firstname.lastname@example.org’ is the IBM i profile and IP address. Clicking the Open button will start a session where you will be prompted for your IBM i profile’s password.
Below we see how to login from a Mac. After logging in, the
pwd (print working directory) command is run so we can learn where we are at in the file system. The next command,
echo $SHELL, is checking to see what shell we are using and in this case it shows bash. The bash shell utility doesn’t come with IBM i by default so the PowerRuby team has ported and included it with our installation (download your free copy here).
SSH shell session is tied to an IBM i job, as shown below. Take option 5 and peruse through the various attributes of that job to see what it has for values, library list, etc. It is important to realize what is going on here because it is significant. We logged into a Linux-like environment yet it is in entire submission to the IBM i operating system kernel which inherently gives us all the security, workload balancing, and other features we’ve come to rely on.
Defaulting to Bash
Now that you are logged in using SSH it would be good to learn some personalization options as it relates to your environment. For example, it is possible to make the PowerRuby bash shell your system-wide default.
/QOpenSys/QIBM/UserData/SC1/OpenSSH/openssh-4.7p1/etc/sshd_config stores name-value-pairs of settings for SSH. You can edit the file with joe from an existing ssh session or EDTF from 5250 green screen, full commands shown below. Note that the joe editor is also included with the PowerRuby download.
ibmpaseforishell line to look like the following:
Here is a sample screenshot of what the joe editor looks like when editing the sshd_config file. The whole screen is editable and there is even syntax coloring for certain file extensions (i.e. Ruby files ending in .rb).
After making changes to the sshd_config file you need to restart the SSH daemon with the following commands:
Sometimes it isn’t a reality to change system-wide settings and instead you may need to only change your profile to be defaulted to a different shell. This can be easily done by creating a
.profile file inside your home directory and then adding the below shell script code to it.
# detect if we're in a PASE shell /QSYS.LIB/QSHELL.LIB/UNAME.PGM > /dev/null 2>&1 if [ $? != 0 -a "$SHELL" != "/QOpenSys/usr/bin/bash" ] then exec /QOpenSys/usr/bin/bash fi
.profile file will be processed when a shell session is started and place you into a bash shell. The reference to
/QOpenSys/usr/bin/bash is actually a symbolic link that points at
If you don’t want to change sshd_config or write a script for .profile there is still the manual way of entering into bash by typing
/PowerRuby/oss/bin/bash in your current SSH session. Note that by doing this you are actually creating a second IBM i job, one for each shell session. To exit the second shell session you can type “exit” and then you will be placed into the initial shell session. Typing “exit” again will log you out of the IBM i shell session.
Increasing Shell Session Timeout
It can be frustrating to have your 5250 telnet sessions timeout, and the same is true for SSH sessions. You can address this by modifying the same sshd_config file:
Search for ClientAliveInterval, remove the pound comment operator (‘#’) and change the setting equal to the number of seconds you’d like your shell to be open until it automatically closes due to no usage. For example, set your system to the following to have a timeout of 30 minutes:
After making changes to the sshd_config file you need to restart the SSH server daemon with the following commands:
That concludes this tutorial on using PASE, SSH, and bash on your IBM i. For a variety of more info on PASE related things you can check out the YiPs (Young i Professionals) wiki. The YiPs wiki is actually very active and new content is frequently being added and changed.
Need help with PASE or Bash on IBM i? Contact us below.