SSH protocol to connect and command others equipemnts on ethernet network

Hello,
I have to power off equipment like NAS and PC by using SSH command.
Could you confirm that we dont have library to connect and send to “other” equipments SSH order?
We have to use LINUX part of PFC200 PLC :frowning:

there is one problem:
we can connect to other device using app
ssh -o StrictHostKeyChecking=no root@ipaddress 'command'
but you have to write the password for security reasons. No password, no problem (except security :stuck_out_tongue: )
To send a password you need sshpass app, so you can send password:
sshpass -p 'password' ssh user@remote_ip 'command'
To do that, you can create some docker container and call it using SysProcess library or WagoAppConfigTool (SSH command from CoDeSys - #4 by WagoDamRud)

Thanks for your celerity :slightly_smiling_face:
But i am old (ladder code generation) and i want to be sure to understand.

I will use WagoAppConfigTool to send to a NAS(IP@ 192.168.1.18) login: admin password:toto the order poweroff.
VAR
myFbConfigTool : FbConfigTool;
sResult : STRING(255);
END_VAR

myFbConfigTool( xExecute := TRUE,
sCallString := ‘sshpass -p toto ssh admin@192.168.1.18 poweroff’,
sResultString => sResult );

IF myFbConfigTool.xDone THEN
myFbConfigTool.xExecute := FALSE;
END_IF

Am i too optimist? :slight_smile:

Okey, the codesys part is almost done, you know how to call config tool script :slight_smile:

but you have to do some steps before.

  1. Can do it only with PFC200 G2 (750-821x) or CC100 or EC or TP600 controller (linux based controllers) with Internet connection (DNS, Gateway, actual time are needed)

  2. Go to WBM (https://plc_ip/wbm) > Configuration > Docker and enable it

  3. Download PuTTY ( Download PuTTY - a free SSH and telnet client for Windows) it is a SSH client, so we can connect do PLC console via SSH

  4. Login with root/wago

BUILD OWN CONTAINER
  1. youre now in /root catalog lets create folder for our solution
    mkdir sshpass
    cd sshpass
  2. Create file with instruction to create small Docker container with sshpass application
    nano dockerfile
  3. Paste this (copy from here and right mouse click in Putty to paste)
FROM arm32v7/alpine:latest
RUN apk add --update --no-cache sshpass openssh
ENTRYPOINT ["sshpass"]
CMD ["-h"]

And press CTRL+x, then Y and enter

  1. Build you own image
    docker build -t sshpass-arm7 .
    The dot is important :wink:
    The output will show something like:

  2. Now you can call you query!
    docker run --rm -it sshpass-arm7 -p 'toto' ssh -o StrictHostKeyChecking=no admin@192.168.1.18 'poweroff'

USE MY CONTAINER
  1. Just call:
    docker run --rm -it damrudwago/sshpass-arm7 -p 'toto' ssh -o StrictHostKeyChecking=no admin@192.168.1.18 'poweroff'"

And in below instruction change everywhere image name:
sshpass-arm7 → damrudwago/sshpass-arm7


Okey, but this script command is quite long, so you can make an ALIAS
alias yournameofthecommandhere="docker run --rm -it sshpass-arm7 -p 'toto' ssh -o StrictHostKeyChecking=no admin@192.168.1.18 'poweroff'"

so now you can just call:
yournameofthecommandhere
to run your power off command!

Now you can use SysProcess to call it directly or in /etc/config-tools/ create new script to use WagoAppConfigTool:
nano /etc/config-tools/myscript1

Paste:

!#/bin/bash
docker run --rm -it sshpass-arm7 -p 'toto' ssh -o StrictHostKeyChecking=no admin@192.168.1.18 'poweroff'"

Add permission to execute your script:
chmod +x /etc/config-tools/myscript1

Now you can call it from your Codesys application:

VAR
  myFbConfigTool : FbConfigTool;
  sResult : STRING(255);
END_VAR

myFbConfigTool( xExecute := TRUE,
sCallString := ‘./myscript1’,
sResultString => sResult );

IF myFbConfigTool.xDone THEN
myFbConfigTool.xExecute := FALSE;
END_IF
1 Like

Thanks Damien.
i wil try it :slight_smile:
Alpine was good this weekend, it is a good sign!

the rain shows the class of the drivers :wink: #F1

I pushed this image to my DockerHub repository, so you can use the “USE MY CONTAINER” solution which is faster then building your own image