Strovent SystemsSign in
Reference

IBM i SSH "Permission denied": home, key permissions, PASE shell

SSH to IBM i fails with Permission denied when HOMEDIR has no .ssh folder, key files are writable by others, the PASE shell is missing, or a name is too long.

When an SSH login to IBM i fails, the client shows only something like Permission denied (publickey,password,keyboard-interactive). The reason is written on the IBM i side by the SSH server (sshd), so read that first, then match it below.

Find the server's reason

  • The sshd job log. IBM says that when the syslog daemon is not set up and running, sshd's messages go to the job log of the sshd job that was started for that connection.
  • A log file. IBM's technote on syslog logging starts syslogd, sends the daemon facility to a file, and sets SyslogFacility DAEMON and LogLevel DEBUG in sshd_config. sshd must be restarted with ENDTCPSVR *SSHD and STRTCPSVR *SSHD after that change.
  • The client. ssh -v [email protected] shows which keys were offered and which methods the server still allows.

"User user1 not allowed because shell ... does not exist"

The profile's PASE shell points to a program that is not there, often an old path from a product that was later removed. sshd treats a user whose shell is missing or not executable as not allowed, so no key or password works.

The shell comes from the profile's PASE shell setting, shown in the PASE_SHELL_PATH column of QSYS2.USER_INFO (null when nothing is set):

SELECT AUTHORIZATION_NAME, PASE_SHELL_PATH, HOME_DIRECTORY
  FROM QSYS2.USER_INFO
  WHERE AUTHORIZATION_NAME = 'USER1'

Set an existing shell, or remove the setting so the default applies:

CALL QSYS2.SET_PASE_SHELL_INFO('USER1', '/QOpenSys/usr/bin/ksh')
CALL QSYS2.SET_PASE_SHELL_INFO('USER1', '')

With no path set, the system default from SET_PASE_SHELL_INFO('*DEFAULT', ...) applies. If that is not set either, sshd uses /QOpenSys/usr/bin/bsh. Setting another user's shell needs *SECADM and *OBJMGT and *USE authority to that profile. Older 5733-SC1 setups can also set one shell for every login with the ibmpaseforishell option in sshd_config; check that path too.

"Authentication refused: bad ownership or modes for directory /home/user1"

sshd's StrictModes check (on by default) refused the key files. authorized_keys and each directory above it, up to the home directory, must be owned by the user (or by root) and must not be writable by group or others. IBM's setup steps, run in a PASE shell (CALL QP2TERM) or Qshell:

chown user1 /home/user1 /home/user1/.ssh /home/user1/.ssh/authorized_keys
chmod 755 /home/user1
chmod 700 /home/user1/.ssh
chmod 600 /home/user1/.ssh/authorized_keys

Check the result with ls -ld /home/user1 /home/user1/.ssh and ls -l /home/user1/.ssh/authorized_keys. The message can also name a file instead of a directory. Changes to these files take effect on the next login; sshd does not need a restart.

The key is ignored and a password is asked for

sshd reads .ssh/authorized_keys in the home directory named by the profile's HOMEDIR. The default, *USRPRF, means /home/ followed by the profile name, but creating the profile does not create that directory; IBM's setup steps create it with mkdir or MKDIR. If the directory is missing, or HOMEDIR names a different one, sshd finds no keys.

  • Check HOME_DIRECTORY with the query above.
  • Create the directory and .ssh folder with the commands above (mkdir /home/user1, mkdir /home/user1/.ssh), or point the profile at the right one with CHGUSRPRF USRPRF(USER1) HOMEDIR('/home/user1').
  • Put the public key, one key per line, in /home/user1/.ssh/authorized_keys. IBM's steps move the key file with FTP in binary mode, so it is not converted on the way.

If the key is there and permitted but the server still skips it, the key type may not be allowed. See SSH "sign_and_send_pubkey: no mutual signature supported".

A profile name longer than eight characters

IBM documents an eight-character limit for profiles that sign on through sshd. It also applies to the user's group profile: if any member of that group has a name longer than eight characters, access is denied. The limit is lifted by the PASE environment variable PASE_USRGRP_LIMITED set to N:

ADDENVVAR ENVVAR(PASE_USRGRP_LIMITED) VALUE('N') LEVEL(*SYS)

Restart sshd afterwards. In IBM i 7.4 the default of this variable changed from Y to N, so the limit mostly affects 7.3 and earlier, or a system where the variable was set back to Y.

"not listed in AllowUsers" or "not in any group"

sshd_config can restrict logins with AllowUsers, AllowGroups, DenyUsers and DenyGroups. IBM notes that the values are case sensitive and that sshd must be restarted after a change. The log line names the rule that matched, for example User user1 from 192.0.2.10 not allowed because not listed in AllowUsers.

Sources

Spotted a mistake? Email [email protected].