Feb 18 2016

SSH, Default Shell and Command History on AS400

Published by at 11:47 pm under AS400




QSHELL and PASE on IBM i are nice tools but remain quite limited with the fixed size 5250 window without 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 start the SSH daemon:

STRTCPSVR SERVER(*SSHD)

 
There’s no autostart option for this TCP server.
I ended up adding above command to the QSTRUP program so it starts automatically upon IPL. You can connect to your AS400 with Putty from now on.
 

Default Shell

The default shell is bsh which is quite limited. It can be changed in the sshd_config file adding

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

as mentioned on IBM website.
 
ksh is also needed to get command history in your terminal.
 

Command History

Once ksh is the default shell, you can configure arrow keys to move within command history.
In the user homedir, create a .profile as follow:

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 and reconnect.
On the 1st line, we check the shell is ksh since the previous changes apply to SSH connections but QSH nor PASE (QP2TERM).
 
This is now 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