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*SSHDin capitals as the server, set Auto Start to*YES, pressF11to 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.
Related
- IBM i SSH "Permission denied": home, key permissions, PASE shell
- IBM i shells: QSH, QP2TERM or SSH, and which to use
- IBM i Telnet connection refused, check that the Telnet server is running
- Connection abort, reset and timed-out errors in SSH and Telnet clients
- Run SQL on IBM i from a 5250 session: STRSQL, RUNSQL and RUNSQLSTM
Sources
- IBM Support: Starting the OpenSSH Server (SSHD) on IBM i 6.1 and above
- IBM Support: How to set up the IBM i SSH daemon to autostart with TCP/IP
- IBM Support: STRTCPSVR *SSHD fails to start the Secure Shell Daemon
- IBM i 7.6 TCP/IP troubleshooting: Server table, Secure Shell daemon
- IBM i 7.5: Start TCP/IP Server (STRTCPSVR)