Last active
April 7, 2023 22:07
-
-
Save alexalouit/74b966b0ee1e073f83ab7648016e2948 to your computer and use it in GitHub Desktop.
OpenWRT as reliable and secure SFTP server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ opkg update | |
$ opkg install openssh-server openssh-sftp-server | |
# disable built-in dropbear | |
$ /etc/init.d/dropbear disable | |
$ /etc/init.d/dropbear stop | |
# enable full openssh server | |
$ /etc/init.d/sshd enable | |
$ /etc/init.d/sshd start | |
# disable dropbear default instance | |
$ uci del dropbear.cfg014dd4 | |
$ uci commit | |
# create sftp group | |
sftp:x:4099:sftp | |
$ nano /etc/group | |
# configure ssh server | |
$ nano /etc/ssh/sshd_config | |
# comment | |
Subsystem sftp /usr/lib/sftp-server | |
# add | |
Subsystem sftp internal-sftp | |
# add | |
Match Group sftp | |
ForceCommand internal-sftp | |
ChrootDirectory %h | |
AllowTcpForwarding no | |
PermitTunnel no | |
X11Forwarding no | |
AllowAgentForwarding no | |
# restart server | |
$ /etc/init.d/sshd restart | |
# for each user (adjust $username, $dir and $i) | |
# add users as : | |
# $username:x:400$i:4099:$username:/$dir:/bin/false | |
$ nano /etc/passwd | |
# add to sftp group (at the end of line, comma-separated) | |
$ nano /etc/group | |
# if we want password login | |
$ passwd $username | |
# create required file | |
$ mkdir /$dir/.ssh | |
$ touch /$dir/.ssh/authorized_keys | |
$ mkdir /$dir/data | |
# create key | |
$ dropbearkey -t rsa -f /$dir/.ssh/id_rsa | |
# set owner permisisons | |
$ chown $username:sftp -R /$dir | |
$ chown root /$dir | |
# restart server | |
$ /etc/init.d/sshd restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment