Strovent SystemsSign in
Reference

IBM i SSH "Connection refused" on port 22: start sshd with STRTCPSVR *SSHD and autostart it

The IBM i SSH server does not start by default. Start it with STRTCPSVR SERVER(*SSHD), check port 22 with NETSTAT, and set it to autostart with TCP/IP.

ssh: connect to host ibmi.example.com port 22: Connection refused usually means the SSH server on IBM i is not running. On IBM i it is a TCP/IP server like Telnet or FTP, but its autostart setting is *NO by default, so after TCP/IP restarts it stays down until someone starts it.

Check and start it

The SSH server comes with licensed program 5733-SC1, which must be installed. From an IBM i command line:

STRTCPSVR SERVER(*SSHD)

The first time, this also creates the server's host keys, so there is nothing to generate by hand. To stop or restart it:

ENDTCPSVR SERVER(*SSHD)
STRTCPSVR SERVER(*SSHD)

Check that it is listening: run NETSTAT, choose option 3, and look for local port ssh (22, press F14 to show numbers) in state Listen. The server runs as job QP0ZSPWP in subsystem QUSRWRK, so WRKACTJOB SBS(QUSRWRK) should list it.

STRTCPSVR runs but nothing listens

STRTCPSVR *SSHD submits a job to the job queue QUSRNOMAX, which feeds subsystem QUSRWRK. If QUSRWRK is not active, or the job queue is held, the job never runs. Start the subsystem with STRSBS QUSRWRK and check the job queue with WRKJOBQ QUSRNOMAX.

IBM also describes starting sshd from QShell when the command does not start it:

QSH CMD('/QOpenSys/usr/sbin/sshd')

If the job starts and then ends, look at its job log; see IBM i job log missing or empty: CHGJOB LOG, LOGCLPGM and pending job logs.

Start it with TCP/IP every time

IBM's technote gives three ways to set the SSH server to autostart. Use one:

  • IBM Navigator for i: Network, TCP/IP Configuration, TCP/IP Configuration Properties, Servers to Start, then check SSHD.
  • SQL, for example in STRSQL:
UPDATE QUSRSYS/QATOCSTART SET AUTOSTART = '*YES' WHERE SERVER = '*SSHD'
  • UPDDTA: UPDDTA FILE(QUSRSYS/QATOCSTART), enter *SSHD in capitals as the server, set Auto Start to *YES, press F11 to change, then exit.

After that, sshd starts whenever TCP/IP starts.

If sshd runs but your login is refused, see IBM i SSH "Permission denied": home, key permissions, PASE shell.

Sources

Spotted a mistake? Email [email protected].