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
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 4 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.
if you looking for a way to return failure from a remote bash script, try:
kill $$
this causes bash to kill itself ($$ evaluates to bash’s pid) and ssh to return 255.