Feb 18 2016

SSH, Default Shell and Command History on AS400

Published by at 11:47 pm under AS400,SSH

QSHELL and PASE on IBM i are nice tools but remain quite limited with the fixed size 5250 window with no scroll bars. Let’s see how to make it better with a secure SSH connection and a few tricks.
 

Launch SSH Daemon

Considering SSH is installed on your AS400 ie 5733SC1 (OpenSSH, OpenSSL, zlib) in LICPGM, you can then start the SSH daemon with this command:

STRTCPSVR SERVER(*SSHD)

 
There is no autostart option for SSH TCP server.
I ended up adding above command to the QSTRUP program so it starts automatically upon IPL. From now on, you can connect to your AS400 with Putty that you can download for free.
 

SSH Default Shell

The default shell on AS400 is bsh which is quite limited, and uncommon on other operating systems. It can be changed in the sshd_config file (located in /QOpenSys/QIBM/UserData/SC1/OpenSSH/openssh-4.7p1/etc), adding

#ibm pase for IBM i shell
ibmpaseforishell /QOpenSys/usr/bin/ksh

as mentioned on IBM website.
 
ksh is also nice to have so you can have command history in your terminal.
 

Command History

Once ksh is the default shell, you can configure arrow keys to move within command history. No need to type the commands over and over!

In the user homedir, create a .profile file, which will be loaded every time you ssh to the AS400:

if [[ $SHELL = "/QOpenSys/usr/bin/ksh" ]]; then
  set -o emacs
  alias __A=`echo "\020"`     # up arrow = ^p = back a command
  alias __B=`echo "\016"`     # down arrow = ^n = down a command
  alias __C=`echo "\006"`     # right arrow = ^f = forward a character
  alias __D=`echo "\002"`     # left arrow = ^b = back a character
  alias __H=`echo "\001"`     # home = ^a = start of line
  alias __Y=`echo "\005"`     # end = ^e = end of line
fi


Now restart the SSH daemon the same way you started it, and reconnect.
On the 1st line, we check the shell is ksh since the previous changes apply to SSH connections only. The .profile is also loaded in QSH and PASE (QP2TERM), which don’t run ksh by default.
 
Connecting with Putty is far more convenient than calling QP2TERM is the 5250 fixed size window!
You can even do the same with bash if it has been installed on your system. Hint: Install 5733OPS Option 3, gcc comes along with bash, perl or even rpm on postintallation.


No responses yet

Trackback URI | Comments RSS

Leave a Reply