-1

I find it costs one more seconds that ssh exec a simple command, does it normal? if not, how to speed up it?

[root@ops-test-vm-154:~]# time ssh root@10.17.1.155 'echo "hello,world!"'
hello,world!

real    0m1.805s
user    0m0.009s
sys 0m0.005s

there is low latency between vm-154 and vm-155

[root@ops-test-vm-154:~]# ping 10.17.1.155
PING 10.17.1.155 (10.17.1.155) 56(84) bytes of data.
64 bytes from 10.17.1.155: icmp_seq=1 ttl=64 time=0.142 ms
64 bytes from 10.17.1.155: icmp_seq=2 ttl=64 time=0.136 ms
64 bytes from 10.17.1.155: icmp_seq=3 ttl=64 time=0.129 ms
64 bytes from 10.17.1.155: icmp_seq=4 ttl=64 time=0.110 ms
^C
--- 10.17.1.155 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4421ms
rtt min/avg/max/mdev = 0.110/0.128/0.142/0.014 ms

BTW: I need check service status real time by executing a script in vm-155, so vm-154 execute command ssh vm-155 status.sh every second. But even a simple command echo helloworld cost one more second. So the solution is terrible. I hope speed up it, or may be a better solution.

Best Wishes!


There is vm-155 /etc/ssh/sshd_config, I add UseDNS no and execute service sshd restart, but still need one more second to echo hello,world!

Protocol 2
SyslogFacility AUTHPRIV
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
UsePAM yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
X11Forwarding yes
UseDNS no
Subsystem   sftp    /usr/libexec/openssh/sftp-server

2 Answers2

-1

One thing that you could try is to run SSH in verbose mode and see at which stage it wastes the most time.

ssh -vvv root@10.17.1.155 'echo "hello,world!"'

And then based on your findings adopt your ssh config file to exclude slow cipher suites and other CPU intensive things. Some tips about that here. However, you will not be able to achieve close to real-time performance over ssh if you establish a new connection every time. You could put your script/command into a loop and set seep value to 1s.

ssh root@10.17.1.155 'while true; do echo "Hello, world!"; sleep 1s; done'

But I would use something that is designed for such application like SNMP protocol. Here is an example configuration: https://www.incredigeek.com/home/snmp-and-shell-script/

357up
  • 134
  • 8
  • Thank your tip. when executing with -vvv, it hang for while when it output `debug2: exec request accepted on channel 0`. I find a time-consuming script in /root/.bashrc. After remove the line, it is back to normal. Referring is [SSH Command Execution Hangs, although interactive shell functions fine](https://stackoverflow.com/questions/5929552/ssh-command-execution-hangs-although-interactive-shell-functions-fine) – jumpgoblin Nov 16 '18 at 09:01
-1

One source of delays during the SSH connection process is DNS lookups by the server. When a client connects to the server, the server can optionally look up the IP address of the client to get its hostname. Depending on a variety of issues, the query may take anywhere from a fraction of a second to ten seconds or more to complete.

The most widely deployed SSH server is OpenSSH. The OpenSSH sshd server has a setting named UseDNS which controls whether it performs DNS queries on incoming connections or not:

UseDNS
Specifies whether sshd(8) should look up the remote host name, and to check that the resolved host name for the remote IP address maps back to the very same IP address.

You should check that UseDNS is set to "no" on the server which you're connecting to.

Kenster
  • 23,465
  • 21
  • 80
  • 106
  • Thank your reply. I add `UseDNS no` and restart service sshd. but still need one more second. I add /etc/ssh/sshd_config in my question – jumpgoblin Nov 16 '18 at 04:04