Getting sshfs to work to z/OS

You can “mount” a remote file system as a local directory over sshfs. (ssh file system).

Getting this working was a challenge. I do not know if it is an FTP problem, or a z/OS problem

The command, from Linux, is

sshfs colin@10.1.1.2: ~/mountpoint

where mountpoint is a local directory, and my z/OS system is on 10.1.1.2

This flows into the SSH daemon (SSHD) on z/OS which handles the handshake and encryption.

For the IBM provided SSHD, the /etc/ssh/sshd_config config file has

Subsystem sftp /usr/lib/ssh/sftp-server 

Where /usr/lib/ssh/sftp-server is the executable to do the work. The IBM supplied object is a load module. You could replace this with a script or other module.

Once the session has been established you can access the files, as if they were on the local system.

What is running on z/OS?

If you use the ps -ef command it displays

     UID        PID       PPID  CMD                                               
OMVSKERN 50397264 67174474 /usr/sbin/sshd -f /etc/ssh/sshd_config -R
COLIN 67174482 50397264 /usr/sbin/sshd -f /etc/ssh/sshd_config -R
COLIN 50397267 67174482 sh -c /usr/lib/ssh/sftp-server
COLIN 83951719 50397267 /usr/lib/ssh/sftp-server

This shows the calling chain – the first (SSHD) is at the top, and the last, /usr/lib/ssh/sftp-server, is doing the work to process the files

The shell used depends on the OMVS(PROGRAM()) defined for the userid.

When did sshfs work?

If I had OMVS(PROGRAM(‘/bin/sh’)) then the sshfs worked ok, I could used the files as expected.

If the program was for bash or for zhs, then the data as seen from Linux was in EBCDIC and so was not usable.

So how do I use zsh or bash?

I got round this problem…

I specified the userid as having OMVS(PROGRAM(‘/bin/sh’)), and changed to use the bash shell in the logon script

If I logon with ssh colin@10.1.1.2 then there are environment variables in /etc/profile and ~/.profile.

SSH_CLIENT="10.1.0.2 44898 22"
SSH_CONNECTION="10.1.0.2 44898 10.1.1.2 22"
SSH_TTY="/dev/ttyp0000"

In my ~/.profile I’ve put (thanks to Kirk Wolf for suggesting the better if interactive shell sta

tement)

# for all interactive sessions use the following if
#if [[ $- = *i* ]];
# for sessions only with ssh use the following ig statement
if [[ ! -z "$ SSH_CONNECTION" ]]
# ssh: switch to bash....
#set -x
# bash="/usr/lpp/Rocket/rsusr/ported/bin/bash"
bash="/u/zopen/usr/local/bin/bash"
echo "shell was $SHELL bash $bash"
if [[ $SHELL != $bash ]]
then
echo "using the bash shell" $bashs
export SHELL="$bash"
exec "$bash" # replace the current script with bash
# any code after the exec is not executed
fi
fi

which says. If the $SSH_CONNECTION variable is not the empty string, (the session came in over an ssh connection) then invoke $bash, and it replaces the current environment with the /u/zopen/usr/local/bin/bash.

With this I could use both sshfs for remote file access, and ssh for terminal access.

If there are better ways of doing this, please let me know

5 thoughts on “Getting sshfs to work to z/OS

  1. Hmmmm! First off – notice the : at the end of the host ip address – VERY important. I got ‘bad mount point’ messages until I noticed it! 😦

    I have OMVS(PROGRAM(‘/bin/sh’)) and echo $SHELL shows: /bin/sh, echo $0 shows: -sh but still the text files I view show as EBCDIC rather than ASCII 😦

    Like

    1. If you use the command ls -T * on the files it will tell you if they have a tag. For example
      lt -T gave
      – untagged T=off extract
      t ISO8859-1 T=on extract.c
      m IBM-1047 T=off extract.o

      Where extract is an executable (strictly it needs to be tagged -b)
      extract.c is in ASCII – I used VSCode on Linux to edit it
      extract.o is the object file.

      Like

      1. Unless I misunderstand. That means you store the extract.c on z/os as ascii and therefore no translation is required?

        I’m confused if that’s so – maybe I want bash as my shell if it will translate?

        Like

      2. I think the use of bash or not is not relevant to the file tagging, unless I’ve misunderstood you

        I have some files tagged as ISO8859-1, some as IBM-1047, and some not tagged. If the file is tagged
        then tools on z/OS should be able to process it, translating it as necessary. If you access it from
        Windows or Linux, it may only display files (as text) in ISO8859-1.

        Like

Leave a comment