To modify the files on the router, it is not as convenient to edit the files locally on the command line, so it is more efficient for me to map the file system of the router as a shared directory and write directly with notepad++.
The basic steps are to install samba-server and configure 2 steps.
0x01
Install samba server
opkg install samba36-server
As long as it goes smoothly, this line of command will complete the installation. If the package cannot be found, you need to update it first.
opkg update
opkg install samba36-server
This command installs the 3.6 version of samba. If the package is not found in the future version upgrade, first check which version of the opkg software source is.
opkg update
opkg list | grep samba
0x02
The configuration file is /etc/samba/smb.conf.template
There is an article that the configuration is /etc/samba/smb.conf but under openwrt, the samba service is restarted and the file is reset.
vi /etc/samba/smb.conf.template
First comment out the invalid users = root line under [global]. If it is not commented out, the root user will be denied login.
#invalid users = root
The next step is to add a shared directory, for example:
[etc]
path = /etc
valid users = root
guest ok = no
admin users = root
#Meaning to create a shared directory named "etc", the location of the directory is /etc, allowing root user to log in and denying visitors.
After the configuration, the root user still cannot log in. It should be said that samba will use the system login name, but will not use the system password for authentication, so you need to set a password for samba
smbpasswd -a root
According to the prompt of the command, enter the authentication password of root, and then use the password to log in to the share.
Finally restart samba
/etc/init.d/samba restart
0x03
Make the above operation into a shell script:
opkg update
package=`opkg list | grep samba36-server | awk '{print $1}'`
opkg install $package
sed -i '/invalid users/s/invalid/#invalid/g' /etc/samba/smb.conf.template
(cat <<EOF
[etc]
path = /etc
valid users = root
guest ok = no
admin users = root
[tmp]
path = /tmp
valid users = root
guest ok = no
admin users = root
[usr]
path = /usr
valid users = root
guest ok = no
admin users = root
[var]
path = /var
valid users = root
guest ok = no
admin users = root
[www]
path = /www
valid users = root
guest ok = no
admin users = root
EOF
) >>/etc/samba/smb.conf.template
smbpasswd -a root
/etc/init.d/samba restart