Warning, this article has been created more than 6 month ago. The information it contains may not be up to date. Check if it is possible to establish a SSH connection with Bash Written by Mirabellette / 20 march 2018 / no comments Hello everyone I am continuing to write an article each month. I add some little title and subtitle to improve the ease of reading. Today, I want to share to you a little trick I use to check if it is possible to establish a SSH connection with a remote host. Introduction Use case You want to transfer some files with SSH protocol. You want to be sure it is possible to establish a connection and be notified if it is not possible. You want to check periodically if it is possible to connect to a remote host with SSH. What I do I created a bash script to open a connection with the remote host in SSH and check if it works well. If it doesn't, I send an email to a specific address. The main part Scripts Both scripts are available in Github following MIT LICENCE. You can find them here. Script to check ssh connection Crontab Requirement and advice You need to have a bash prompt after you connected to ssh. You need to have a mail transfer agent properly configured. You need to check when you established a SSH connection that you don't receive any warning message from SSH. In this case, the status variable will got another value than "ok" and the script will considered you aren't be able to establish a connection. Sources https://stackoverflow.com/questions/1405324/how-to-create-a-bash-script-to-check-the-ssh-connection/11562762#11562762 Conclusion I know that it must be a better way to test that but it fit well for my use cases. Social media If you find this article interesting, feel free to subscribe to my RSS flux and to follow me on Mastodon. Don't hesitate to share it if you think he could interest someone else.