SSH client is a program for logging into a remote machine and for executing commands on a remote machine. By default in Linux/UNIX if particular command/shell script is executed, it return two type of values which is used to see whether command or shell script executed is successful or not. This value is know as Exit Status of shell command or script.
The session terminates when the command or shell on the remote machine exits and all X11 and TCP/IP connections have been closed. The exit status of the remote program is returned as the exit status of ssh. You can use bash shell $? Variable to print exit status of shell. For example:
user@localhost: $ ssh user@somewhere.com
Password:
user@somewhere.com: $ exit
user@localhost: $ echo $?
In short,
- ssh exits with the exit status of the remote command which can be find with echo $? command.
- Or value 255 is return, if an error occurred while processing request via ssh session
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -

{ 3 comments… read them below or add one }
Very well, but what ARE the exit stati of the ssh command?
e.g, 0 if succesful? Or, 1?
Seeing as this is the top hit for googling “ssh return status”, I thought I’d go ahead and add that
So you don’t *always* get the return status of your program.
Good post, though….it answered my question :)
My SSH version returns 0 for okay, and 255 if connection failed.