Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8422543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:28:45+00:00 2026-06-10T03:28:45+00:00

ssh -q -o BatchMode=yes user@host echo 2>&1 && echo OK || echo NOK this

  • 0
ssh -q -o "BatchMode=yes" user@host "echo 2>&1" && echo "OK" || echo "NOK"

this method is suitable but it returns true when the pub.key is copied to host.
I need to see if an ssh is connectiable between two devices without keys.

Simply wants to check if the sshd is running remotely.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:28:47+00:00Added an answer on June 10, 2026 at 3:28 am

    If you just want to check if you can connect to a host via ssh, you could simply check if port 22 is open. There are various ways to to this.

    Using nmap (replace localhost with your target host):

    $ nmap -p22 localhost
    
    Starting Nmap 5.21 ( http://nmap.org ) at 2012-08-15 13:18 BST
    Nmap scan report for localhost (127.0.0.1)
    Host is up (0.000044s latency).
    PORT   STATE SERVICE
    22/tcp open  ssh
    
    Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds
    

    To use this in a script:

    if nmap -p22 localhost -oG - | grep -q 22/open; then 
        echo "OK"
    else 
        echo "NOK"
    fi
    

    You can also use netcat:

    $ nc -zv localhost 22
    Connection to localhost 22 port [tcp/ssh] succeeded!
    

    To use this in a script:

    if nc -zv localhost 80 2>&1 | grep -q succeeded; then 
        echo "OK"
    else 
        echo "NOK"
    fi
    

    This is a quick check which is sufficient in most situations, however it is not fool-proof. There is no guarantee that the service listening on the remote port is actually an SSH server.

    You could attempt a dummy connection and inspect the returned header, e.g:

    $ echo "dummy" | nc localhost 22
    SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
    Protocol mismatch.
    

    however such an approach is undesirable for various reasons. The only guaranteed way would be to establish an actual connection as you’ve shown in your question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our capistrano setup is: ssh with regular user, but deploy to a location requiring
I've got an ssh key in ~/.ssh/id_rsa.pub when I login as the jenkins user.
ssh $hname cd /opt/tomcat/webapps/aware/WEB-INF/classes/com && for FNAME in `tar tvf /tmp/prop.tar | awk '{print
system(ssh test.host.com); its asking for permentaly add key or not ? I want automatically
I ssh to another server and run a shell script like this nohup ./script.sh
ssh -i [full path to keypair file] ec2-user@[EC2 instance hostname or IP address] I
When I run ssh git@host repo I receive list of my permissions It says
I'm spawning an ssh process in my python script like this: env = {'SSH_ASKPASS':'/home/max/repo/vssh/vssh/vssh.py',
I wanna tunnel my ssh though port 80(listened by apache). mod_proxy & mod_proxy_connect provide
$ git clone ssh://host/repo.git ~/ destination directory '/home/username/' already exists. Can anyone tell me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.