Building openwrt image with openssh-server

``im trying to build an image with packages"-dropbear openssh-server" it installs openssh-server but i cannot access luci nor ssh in because it requires a password i have tried adding my keyfile in files/root/.ssh/authorized_keys

also tried setting a password like this:

mkdir ./files/etc/uci-defaults/
cat <<'__EOF__' > ./files/etc/uci-defaults/99_default-password.sh
#!/bin/sh

[ "$(uci -q get system.@system[0].init)" = "" ] && exit 0
[ -e /etc/init ] && exit 0
touch /etc/init
uci batch <<EOC
    set system.@system[0].init='initiated'
    commit
EOC

/usr/bin/passwd root <<EOP
password
password
EOP
exit 0 # IMPORTANT, IF WE NO PUT THIS, WILL EXECUTED ENDLESSLY
__EOF__

all to no avail i hope someone has a suggestion

i also tried putting the sshd_config in /etc/ssh/ to permit root login but still nothing, is there something that happens during the dropbear installation that makes the password empty? because luci and ssh both want a password that i dont know nor can i find where that has been set

LuCI login should not be effected by changing dropbear to ssh. LuCI does not have set a password initially. It only has if you decide on an upgrade to preserve settings. Your script to set a password looks a bit overkill to me.

A simple one-liner will do it:

echo -e 'MyPassWord\nMyPassWord' | passwd root

Beside that you need sshd_config placed with allowing root login also. In case you want dropbear paralell installed you have to adjust ports as well.

Port 2222 # or whatever port you want
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes
PermitEmptyPasswords no

Put this just at the end of the regular sshd_config and place it accordingly /files/etc/ssh/ like the 99_default-password.sh script.

still no dice and i dont know why it requires a password either but i am not replacing dropbear with openssh-server i dont install dropbear at all maybe the issue is there

i build the image with the following line:

make image PROFILE="rpi-4" PACKAGES="bash luci-ssl nano shadow sudo openvpn luci-app-wireguard wireguard-tools luci-app-vpnbypass openssh-server luci-app-pbr luci-app-ddns -dropbear" FILES="files"

the following is the sshd_config i put

strange@echelon:~/Downloads/install/openwrt/pi4.imagebuilder/files/etc/ssh$ cat sshd_config 
#	$OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile	.ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to no to disable s/key passwords
#KbdInteractiveAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin prohibit-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
#UsePAM no

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem	sftp	/usr/lib/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	PermitTTY no
#	ForceCommand cvs server
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes
PermitEmptyPasswords no

i've tried running it with just that and i get password failures then
so then i've tried your echo way of setting a password:

strange@echelon:~/Downloads/install/openwrt/pi4.imagebuilder/files/etc/uci-defaults$ cat 99_default-password.sh 
#!/bin/sh

[ "$(uci -q get system.@system[0].init)" = "" ] && exit 0
[ -e /etc/init ] && exit 0
touch /etc/init
uci batch <<EOC
    set system.@system[0].init='initiated'
    commit
EOC

echo -e 'test\ntest' | passwd root
exit 0 # IMPORTANT, IF WE NO PUT THIS, WILL EXECUTED ENDLESSLY
strange@echelon:~/Downloads/install/openwrt/pi4.imagebuilder/files/etc/uci-defaults$ 

same error on trying to ssh root@10.0.0.1 get a response but wont accept password "test"

i should flash factory image right?

1.) I don't really know where you've got the script above. For me it looks like it does unnecessary stuff. There is no /etc/init file on my installation. So its outdated at least. Delete it and use the one-liner only.

2.) You've configured the device for 10.0.0.1 in an extra config file correctly?

3.) Just try out if dropbear is a hard requirement and install both. It won't hurt for testing. Kepp in mind to adjust listen ports.

4.) You use factory image for initial installation only. If you've installed it already use sysupgrade.

thank you i didnt need the clutter indeed

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.