I've needed to do the same thing.
Here's how to boot the Ubuntu Linux subsystem with all of cron's services upon the Windows boot & provide a means to 'reboot' the Linux subsystem.
I'm successfully hosting the openssh-server, nginx & mariadb database on our server.
Install Linux Subsystem
Remove sudo password prompt (required)
Enable SSH password login (optional)
Windows autologin on start (required if you have a password or RDP in)
Run bash/cron loop on start
Add apps/services to startup on cron
- Open bash
sudo crontab -e
- Select nano (or any editor you know how to save in)
Append startup apps such as openssh-server, nginx, mysql, php:
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@reboot . $HOME/.profile; /usr/sbin/sshd -D
#@reboot . $HOME/.profile; service php7.1-fpm start # Uncomment for php7.1 fpm
#@reboot . $HOME/.profile; service mysql start # Uncomment for mysql/mariadb
#@reboot . $HOME/.profile; service nginx start # Uncomment for nginx
Save and exit: ctrlx, then press y and enter.
Reboot the Linux subsystem without rebooting Windows
Extra - Install PHP 7.1 (not quite as straight forward)
Run the commands below for a pretty standard setup:
mkdir /run/php && chmod -R 777 /run/php
sudo add-apt-repository ppa:ondrej/php && sudo apt update
PHPV=7.1 && sudo apt install --allow-unauthenticated -y php${PHPV}-fpm php${PHPV}-gd php${PHPV}-json php${PHPV}-mysqlnd php${PHPV}-curl php${PHPV}-intl php${PHPV}-mcrypt php${PHPV}-imagick php${PHPV}-zip php${PHPV}-xml php${PHPV}-mbstring
Run the command below for an 'OwnCloud' setup:
PHPV=7.1 && apt install --allow-unauthenticated -y php${PHPV}-redis redis-server php${PHPV}-ldap php${PHPV}-smbclient
Extra - Install nginx webserver
Run the commands below for a base setup with PHP7.1:
sudo add-apt-repository ppa:nginx/stable
sudo apt update && sudo apt -y install nginx
sudo sed -i 's:access_log /var/log/nginx/access.log;:access_log off;:g' /etc/nginx/nginx.conf
sudo sed -i '/index index.html/c\\tindex index.html index.php index.htm index.nginx-debian.html;' /etc/nginx/sites-available/default
STR='}\n\n\tlocation ~ \.php$ {\n\t\tinclude snippets\/fastcgi-php.conf;\n\t\tfastcgi_pass unix:\/var\/run\/php\/php7.1-fpm.sock;\n\t}'
sudo sed -i "0,/}/s//$STR\n/" /etc/nginx/sites-available/default
sudo service nginx restart
Extra - Install mariadb's mysql database
Run the commands below for a mysql database server:
RELEASE=`lsb_release -a | tail -1 | cut -f2`
sudo apt install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository "deb [arch=i386,amd64,ppc64el] https://mirrors.evowise.com/mariadb/repo/10.3/ubuntu $RELEASE main"
sudo apt update && sudo apt --allow-unauthenticated -y install mariadb-server
When prompted, set a root database user password.
UsePrivilegeSeparation = yes, except that one needs to also runsudo /bin/mkdir -p /var/run/sshd(to create the privilege separation directories) before starting sshd. Does WLS now support chroot(), is there a workaround in place in the openssh source, or is the= Nosetting more of a safety recommendation? Also, the windows task seems to only work for me if my user is logged in. – init_js Dec 11 '17 at 23:12/etc/ssh/sshd_configthat readsPort 22and switch toPort 8822. One reason for this is Windows running some sort of SSH process on 22. I've seen suggestions saying there's no problem with disabling that, but I found it easiest to just switch the WSL SSH port. – knickum Apr 06 '18 at 14:48