OpenWrt Forum Archive

Topic: SOLVED: Enabling ssh by script

The content of this topic has been archived on 22 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

When you first build an openwrt device, you telnet into it and enable ssh by creating a password.
I have an odd situation where my build didn't allow ssh but I did include a script which the device picks up when it boots and that seems to be working.

So the question is, what command line commands could I send the device via the script that would enable ssh access? At this time, there are no services what so ever running on it but it does boot and does pick up that script so I have a chance at recovery smile

(Last edited by projects on 17 Apr 2016, 00:06)

uci set dropbear.@dropbear[0]=dropbear
uci set dropbear.@dropbear[0].Port=22
uci set dropbear.@dropbear[0].Interface=lan
uci set dropbear.@dropbear[0].RootPasswordAuth=on
uci set dropbear.@dropbear[0].PasswordAuth=on
uci commit dropbear

Nice, thank you.
I'll try adding this to a script and see if it gets me into the device.

I tested this a lot and here is what I found.

I found that the device is definitely picking up the script from the server when it reboots.
I removed the script from the server to see if the device is actually picking it up and it is. It would not run the script until I put it back and it was able to pick it up.

However, no matter what commands I put in the script, the device never runs any of it but it does run one small function in the script confirming that it is running the script.

This is completely weird and I cannot gain access to that device nor can I even get into a rescue mode.

What a waste, 3 dead, 2 to go.

Seems you have much bigger problems than just ssh.

Some of this may be obvious, but since it wasn't explicitly stated:

### Step 1/3: Create a password for root (otherwise sshd wont allow logon)...
    (echo "p@ssw0rd"; sleep 1; echo "p@ssw0rd") | passwd root

### Step 2/3: Configure DropBear appropriately...
  uci set dropbear.@dropbear[0]=dropbear
  uci set dropbear.@dropbear[0].Port=22
# uci set dropbear.@dropbear[0].Interface=lan ## leave out for troubleshooting
  uci set dropbear.@dropbear[0].RootPasswordAuth=on
  uci set dropbear.@dropbear[0].PasswordAuth=on
  uci commit dropbear

### Step 2/3: Restart DropBear to effect the change
  /etc/init.d/dropbear restart

(Last edited by zxdavb on 4 Apr 2016, 22:43)

zxdavb wrote:

Some of this may be obvious, but since it wasn't explicitly stated:

### Step 1/3: Create a password for root (otherwise sshd wont allow logon)...
    (echo "p@ssw0rd"; sleep 1; echo "p@ssw0rd") | passwd root

Very creative!
I just write the password hash directly to /etc/shadow with sed. wink

stangri wrote:

Seems you have much bigger problems than just ssh.

Not sure what this means.
This is another thread I started when trying to deal with this device.
https://forum.openwrt.org/viewtopic.php … 85#p317585

I've not had so many issues with other devices I've configured but these are driving me up a wall. I very much would like a sub $20.00 two port device and this device would be perfect if I could ever get one to work.

(Last edited by projects on 5 Apr 2016, 16:00)

zxdavb wrote:

Some of this may be obvious, but since it wasn't explicitly stated:

### Step 1/3: Create a password for root (otherwise sshd wont allow logon)...
    (echo "p@ssw0rd"; sleep 1; echo "p@ssw0rd") | passwd root

### Step 2/3: Configure DropBear appropriately...
  uci set dropbear.@dropbear[0]=dropbear
  uci set dropbear.@dropbear[0].Port=22
# uci set dropbear.@dropbear[0].Interface=lan ## leave out for troubleshooting
  uci set dropbear.@dropbear[0].RootPasswordAuth=on
  uci set dropbear.@dropbear[0].PasswordAuth=on
  uci commit dropbear

### Step 2/3: Restart DropBear to effect the change
  /etc/init.d/dropbear restart

To make 100% sure I don't make any mistakes, could you turn this into a bash script. I'll reboot the device and let it pick up only this code.

Could someone kindly turn the above into what I need to put into a bash script please.
I cannot get this to work, have been sitting here for days unable to try much more.

UPDATE: Never mind, I used the example and it runs on a test device.
Now to test it on the nexx and see what happens.

(Last edited by projects on 6 Apr 2016, 16:21)

So, I tested this on another device and the code runs fine, changes/enables the ssh port as it should.
I could see the Nexx picking up the script but nothing else after that.

Another odd thing is that every time I restart the device, it comes up with a new MAC address. It's shown something like 20 different ones so far.

projects wrote:
stangri wrote:

Seems you have much bigger problems than just ssh.

Not sure what this means.
This is another thread I started when trying to deal with this device.
https://forum.openwrt.org/viewtopic.php … 85#p317585

I've not had so many issues with other devices I've configured but these are driving me up a wall. I very much would like a sub $20.00 two port device and this device would be perfect if I could ever get one to work.

Which OpenWrt build are you using exactly? Seems like your router is amnesiac and losing ssh settings is not the only of your problems.

stangri wrote:
projects wrote:
stangri wrote:

Seems you have much bigger problems than just ssh.

Not sure what this means.
This is another thread I started when trying to deal with this device.
https://forum.openwrt.org/viewtopic.php … 85#p317585

I've not had so many issues with other devices I've configured but these are driving me up a wall. I very much would like a sub $20.00 two port device and this device would be perfect if I could ever get one to work.

Which OpenWrt build are you using exactly? Seems like your router is amnesiac and losing ssh settings is not the only of your problems.

https://forum.openwrt.org/viewtopic.php … 85#p317585
Image Builder 15.05 is what I used with the two I've lost so far.
This other thread is related to this.

(Last edited by projects on 6 Apr 2016, 23:19)

The issue was simply that I needed to add the dropbear file in /etc/config to allow ssh.

config dropbear
        option PasswordAuth 'on'
        option RootPasswordAuth 'on'
        option Port         '22'
#       option BannerFile   '/etc/banner'

That's it, nothing else. The lost device is in my container of dead devices until a time when I can restore them.

Thanks for all the help.

The discussion might have continued from here.