How to establish shh from Matlab (or how to start programm on remote computer by sending the matlab command on Windows)

70 views (last 30 days)
For my experiment I need to send the command from matlab (which is running on windows) to the linux (running on the remote computer).
The first idea was to use putty and to find the way how to send the command from matlab to putty. But I found no solution for this problem.
In matlab community I found ssh2 function which is looking useful. But if I put in the command window
  • ssh2_simple_command('username@name_of_pc','username',passwort','ls -la *ninjas*')
I receive an error “SSH2 could not connect to the ssh2 host - ‘username@name_of_pc'.
I would be very grateful if you could give me an advice, how to solve this problem.
Many thanks in advance

Answers (1)

Rashed Mohammed
Rashed Mohammed on 8 Mar 2021
Hi Inna,
It seems that remote computer is not accessible from your computer. I've tried the command you've mentioned and it worked perfectly fine for me. Please verify whether remote computer is accessible from your computer or not using the command "ping <remote_computer_hostname>". If the previous command doesn't give error, then try SSH'ing using other software such as Putty to check if it is a problem with MATLAB only.
Hope this helps
  2 Comments
Inna Forsiuk
Inna Forsiuk on 8 Mar 2021
Hi Rashed,
thank you for your reply.
If I use the command prompt (CMD) I can send ssh username@hostname and it asks for the password. After entering the correct password the connection is established.
When I try to use the ssh2 function in MATLAB it went like this:
ssh2_config = ssh2_config('HOSTNAME','USERNAME','PASSWORT');
ssh2_command(ssh2_conn, 'ls -la *ninjas*');
but I get the following answer:
Error using ssh2_main (line 86)
Error: SSH2 could not connect to the ssh2 host - "HOSTNAME"!
Error in ssh2 (line 84)
ssh2_struct = ssh2_main(ssh2_struct);
Error in ssh2_command (line 31)
ssh2_struct = ssh2(ssh2_struct);
What might be the reason? Do I miss some requirements?
Thanks for your advice.
Inna
Rashed Mohammed
Rashed Mohammed on 8 Mar 2021
Thanks for getting back. I have looked at the File Exchange submission's comments section and it seems that others have had a similar issue. One user has posted a workaround which worked for him. Please try the mentioned workaround. If the issue still persists, feel free to contact the author of the submission directly.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!