Run /etc/rc.local in Windows subsystem for Linux

user-pic
Vote 0 Votes

Windows 10 的 Linux 子系統 (Windows subsystem for Linux, WSL) 因為不是走一般的開機流程,
所以服務都不會啟動, 也包含了 /etc/rc.local
若要在開啟 WSL 視窗時執行 rc.local, 做法如下(Ubuntu環境)

# 設定 sudo 免密碼
echo "yourusername ALL=(root) NOPASSWD: ALL" >> /etc/sudoers
# 在 bash.bashrc 最後觸發啟動 rc.local
echo "sudo /etc/rc.local &" >> /etc/bash.bashrc

建立 ssh host key
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

建立 /etc/rc.local, 下面內容是啟動 sshd 及 Apache 的範例, 每開一次視窗, 就會被觸發執行.
加在這裡的 script, 需考慮到多開視窗, 就會啟動多次的情況, 所以用 pidof 判斷服務是否已經在跑了, 沒有才啟動服務.

範例:
#!/bin/bash
mkdir -p /run/sshd
pidof -s sshd > /dev/null || /usr/sbin/sshd
pidof -s apache2 > /dev/null || service apache2 start 2>/dev/null

About this Entry

This page contains a single entry by Pank published on May 30, 2019 10:06 AM.

Fixed Windows 10 overscan/underscan issues on an ATI card without Catalyst Control Center was the previous entry in this blog.

Basic IPv6 firewall rule for RouterOS is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives