Logic Machine Forum
Cannot generate ssh key - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Cannot generate ssh key (/showthread.php?tid=3349)



Cannot generate ssh key - baggins - 07.05.2021

Hi,

Strange problem.
After a reboot, a script that uses ssh to another server stopped working.
I found that the ssh key had disappeared from /lib/genohm-scada/storage.

I wanted to generate a new key with:

Code:
key = '/lib/genohm-scada/storage/id_rsa'
res = os.execute('dropbearkey -t rsa -f ' .. key)
log(res)
keyinfo = io.readproc('dropbearkey -y -f ' .. key)
log(keyinfo)
but no key is generated:

Code:
testing 07.05.2021 17:26:49
* string:
testing 07.05.2021 17:26:49
* number: 35584
Any idea what might be going on?
Thanks.


RE: Cannot generate ssh key - admin - 07.05.2021

Maybe the SD card is read-only? This will explain disappearing files after a reboot.


RE: Cannot generate ssh key - baggins - 07.05.2021

(07.05.2021, 15:45)admin Wrote: Maybe the SD card is read-only? This will explain disappearing files after a reboot.

That key was there since a long time and it is only a month or so that I replaced the card...
I just rebooted the machine again and the test script that I created an hour ago is still there so the card seems to be ok..

What does the return code 35584 from the os.execute mean?


RE: Cannot generate ssh key - admin - 08.05.2021

Try running it like this. It might provide some info on what's wrong:
Code:
key = '/lib/genohm-scada/storage/id_rsa'
res = io.readproc('dropbearkey -t rsa -f ' .. key .. ' 2>&1')
log(res)
keyinfo = io.readproc('dropbearkey -y -f ' .. key .. ' 2>&1')
log(keyinfo)



RE: Cannot generate ssh key - baggins - 08.05.2021

(08.05.2021, 10:15)admin Wrote: Try running it like this. It might provide some info on what's wrong:
Code:
key = '/lib/genohm-scada/storage/id_rsa'
res = io.readproc('dropbearkey -t rsa -f ' .. key .. ' 2>&1')
log(res)
keyinfo = io.readproc('dropbearkey -y -f ' .. key .. ' 2>&1')
log(keyinfo)

Segmentation fault!

Code:
testing 08.05.2021 12:48:52
* string: Failed reading '/lib/genohm-scada/storage/id_rsa'

testing 08.05.2021 12:48:52
* string: Generating key, this may take a while...
Segmentation fault



RE: Cannot generate ssh key - admin - 08.05.2021

Try changing the key file name to something else and check if the key generation fails or not. This indicates a possible hardware (CPU or RAM) fault. It can cause various issues like scripts failing randomly or services not working correctly.


RE: Cannot generate ssh key - baggins - 08.05.2021

(08.05.2021, 14:30)admin Wrote: Try changing the key file name to something else and check if the key generation fails or not. This indicates a possible hardware (CPU or RAM) fault. It can cause various issues like scripts failing randomly or services not working correctly.

Same result with another file name.
Rebooted the machine and repeated: same result.

Shutdown the machine and powered down. Restarted: same result.
Tried with a dss key instead of rsa: same result.

Is there some logfile similar to the normal /var/log/messages that I could look at?
Some other process that I could run to see if there are also problems with that?

Thanks.


RE: Cannot generate ssh key - admin - 10.05.2021

I suspect this is a hardware problem so monitoring won't solve it. Send us an e-mail, maybe we can arrange a replacement CPU module for you.


RE: Cannot generate ssh key - baggins - 19.05.2021

(10.05.2021, 06:50)admin Wrote: I suspect this is a hardware problem so monitoring won't solve it. Send us an e-mail, maybe we can arrange a replacement CPU module for you.

With the generous help from openrb I managed to replace the CPU module (thanks Edgars!). I would like to take this opportunity to emphasize the great level of support that we receive here!

Unfortunately this did not resolve the problem: I still get the segmentation fault:

Code:
testing 19.05.2021 09:06:21
* string: Generating key, this may take a while...
Segmentation fault

Even if this would have worked I ran into another issue: the library that prevents me from upgrading this LM complains about the license key.
I can see that the daemon reads the license key but apparently this is linked to the MAC address of the LM which changed also together with the CPU...

I wonder if I could copy the ssh key from another LM to this one?


RE: Cannot generate ssh key - admin - 19.05.2021

This script will create a key that has been generated on another LM:
Code:
key = 'AAAAB3NzaC1yc2EAAAADAQABAAABAQCyAiQPWmdF+BK4zJb8KIbebYH03v+K8x4mq6sK59k9t1dstpF5Um8LUK2dpwdcdI3hYme1fIwPvMJd3a/1GN06lnW+ASGSRalDxK0H7WXiKBnGpNMKo0SfKbd4+fXNUjdiemjYCGev1WP66MUq3bw9PN2ISXkm5YjOnvARwZVvK5JlXAo67Jsy0J2UXDX1EAEz7ekGx/RcpBPFzQzLEDG4j1Ny1QVfBsi7V9qfuf9L+mxqulpDy5FAG0Pksmzx/8XCL4a0c7iAvehi+5svMBCpS0zraf9W2rtdTaX7TH6zfv2ORxIDP1BIhQi4W9+zvETZPgU8i6VqyFfxDAgQ0TnTAAABADbUBftcoxagFFQrYA4HBZOZM0ATN666t3y9v486XmVuBVWM3j36MA3SKce3XMMTe2gCgWMbG6D1SQDUeZAKuomDMnz1qDt/jWU8PPeGHa2NIHNY7VAHfelwVfzDMPyu6DRC8+wmmplEJulvrNtJNOO/zZRe3Rwn8v2BYvx1HewBgYuNEyyTnBYGxFejYg08yOY/88C4aHJ5CYitHlSa+xPWV3jV/5uydNlsix2qFK9sKz+Un62oqAVz8ldBdFgFiBGiYvftTAPbkhnI5KsWawvFL3Q3azT0TuIzdfJE/TGUZkx5wSPxy3JGqTwkqw9O3TuoBrxnyxm2ikhLWjc/zeEAAACBAME4q9IQTTAzgm/T+0G4osRsOmkHJtPrlxAghYfIBb6y/7spdHRjA+PPFvCicKS4EUj4xUM6c98rXWaA/CunYxWVdR8tjmWsm592o51GHVR4LepgdmUeey70hIKgAvMCtrTy2jpjdV0FrjPOOrZCRNtQViR71i62I4rpiytr02r5AAAAgQDr2B3Veql0KIlftrFwNTzxQgv+z4L6tsiH8s8ncnle30s405fNwr0CWMTZ7mhyHzmVvTBgFOEFYBlOF6XGAM3XulsHFq58sK4eJGLEDh3KzJgHvzDJuPM4bBqhkmRCyXEB2wMnptqFTofaovwDeTQWylrFvAj+dexAbOnp4H7SKw=='
key = require('encdec').base64dec(key)
io.writefile('/lib/genohm-scada/storage/id_rsa', key)
os.execute('chmod 0600 /lib/genohm-scada/storage/id_rsa')



RE: Cannot generate ssh key - baggins - 19.05.2021

(19.05.2021, 07:56), because that oneadmin Wrote: This script will create a key that has been generated on another LM:
Code:
key = 'AAAAB3NzaC1yc2EAAAADAQABAAABAQCyAiQPWmdF+BK4zJb8KIbebYH03v+K8x4mq6sK59k9t1dstpF5Um8LUK2dpwdcdI3hYme1fIwPvMJd3a/1GN06lnW+ASGSRalDxK0H7WXiKBnGpNMKo0SfKbd4+fXNUjdiemjYCGev1WP66MUq3bw9PN2ISXkm5YjOnvARwZVvK5JlXAo67Jsy0J2UXDX1EAEz7ekGx/RcpBPFzQzLEDG4j1Ny1QVfBsi7V9qfuf9L+mxqulpDy5FAG0Pksmzx/8XCL4a0c7iAvehi+5svMBCpS0zraf9W2rtdTaX7TH6zfv2ORxIDP1BIhQi4W9+zvETZPgU8i6VqyFfxDAgQ0TnTAAABADbUBftcoxagFFQrYA4HBZOZM0ATN666t3y9v486XmVuBVWM3j36MA3SKce3XMMTe2gCgWMbG6D1SQDUeZAKuomDMnz1qDt/jWU8PPeGHa2NIHNY7VAHfelwVfzDMPyu6DRC8+wmmplEJulvrNtJNOO/zZRe3Rwn8v2BYvx1HewBgYuNEyyTnBYGxFejYg08yOY/88C4aHJ5CYitHlSa+xPWV3jV/5uydNlsix2qFK9sKz+Un62oqAVz8ldBdFgFiBGiYvftTAPbkhnI5KsWawvFL3Q3azT0TuIzdfJE/TGUZkx5wSPxy3JGqTwkqw9O3TuoBrxnyxm2ikhLWjc/zeEAAACBAME4q9IQTTAzgm/T+0G4osRsOmkHJtPrlxAghYfIBb6y/7spdHRjA+PPFvCicKS4EUj4xUM6c98rXWaA/CunYxWVdR8tjmWsm592o51GHVR4LepgdmUeey70hIKgAvMCtrTy2jpjdV0FrjPOOrZCRNtQViR71i62I4rpiytr02r5AAAAgQDr2B3Veql0KIlftrFwNTzxQgv+z4L6tsiH8s8ncnle30s405fNwr0CWMTZ7mhyHzmVvTBgFOEFYBlOF6XGAM3XulsHFq58sK4eJGLEDh3KzJgHvzDJuPM4bBqhkmRCyXEB2wMnptqFTofaovwDeTQWylrFvAj+dexAbOnp4H7SKw=='
key = require('encdec').base64dec(key)
io.writefile('/lib/genohm-scada/storage/id_rsa', key)
os.execute('chmod 0600 /lib/genohm-scada/storage/id_rsa')

I will give that a try.
I suppose I can use the key that I have on my other LM because that one is already on the server that I want to ssh to?


RE: Cannot generate ssh key - baggins - 19.05.2021

Well, I copied the key from my other LM4 but that did not help... I could not make a connection to the server. The ssh command returned a 35584 error (?)

After investigation It appeared that dropbearkey and ssh are both linked to /usr/sbin/dropbear and since dropbearkey gave a segmentation fault, it is very likely that ssh will not function also...

Is there anything else I could try?
Thanks.