2022/01/26

Mount sshfs on linux or windows

 Linux

    Install fuse and sshfs
        #sudo apt-get install fuse sshfs

    Mount
        usage: sshfs [user@]host:[dir] mountpoint [options]
        example:
            #sshfs aimwang@192.168.1.253:/home/aimwang /home/aimwang/nas1

    If you want to give the host direct access in WSL, you need to enable user_allow_other.

        Enable user_allow_other:
            Edit /etc/fuse.conf
            Uncomment user_allow_other

        Mount by your id
            Get user/group id number
                #id -u aimwang
                #id -g aimwang
        Mount with a specific user and group id
                #sshfs -o uid=1000,gid=1000,allow_other nas1:/home/aimwang /home/aimwang/nas1

Windows

    Install WinFsp, SSHFS-Win and SSHFS-Win-Manager.

    Execute SSHFS-Win-Manager
        

    
    Click [Add Connection]


    Fill the connection information.


    Click the connect button.
            



    You can see that it is mounted on the specified disk letter, when the connected.





2022/01/24

使用 WSL2 建構 Ubuntu 16.04 的環境

安裝

    公司的編譯伺服器使用 Ubuntu 16.04, 為了減低編譯環境造成的影響, 所以在本機編譯環境也採用相同的版本.

    Windows Store 沒有提供 Ubuntu 16.04, 所以要手動安裝

        1. 下載 Ubuntu 16.04 的 appx. (連結)

        2. 執行 Windows PowerShell, 切換到下載目錄.

        3. 在 PowerShell 裡面執行 Add-AppxPackage .\Ubuntu_1604.2019.523.0_x64.appx

    完成後就可以看到 Ubuntu 16.04 的應用程式. 第一次執行要設定使用者.


檔案系統

    打開檔案總管應該就能看到 WSL 的資夾, 各資料夾進去都是對到 / 根目錄.

    如果沒有看到, 也可以使用 \\wsl$ 進入.

    這真是太方便了, winsshfs 跟 samba 都省下來了.


sudo 免密碼

    #echo "aimwang ALL=(ALL:ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/aimwang


固定IP

    [無效]
    為了方便使用慣用的 ssh client, 還是要設定成固定 IP
    #sudo nano /etc/network/interfaces.d/eth0.cfg
    auto eth0
        iface eth0 inet static
        address 172.19.240.2
        netmask 255.255.240.0
        gateway 172.19.240.1
        dns-nameservers 172.19.240.1


    [host 端的 vEthernet 沒有固定 IP 無意義]

    執行, 或加入開機 task
        
wsl -d Ubuntu-16.04 -u root ifconfig eth0 172.19.240.2 netmask 255.255.240.0
        wsl -d Ubuntu-16.04 -u root rout add default gw 172.19.240.1

啟動 SSH server

    立即啟動 ssh server
    #service ssh start

    開機自動啟動
    #sudo systemctl enable ssh
        無效, 提示改用
            #/lib/systemd/systemd-sysv-install enable ssh
            也是無效
            rc?.d 裡面有看到 S02ssh, 但是似乎沒有去執行.
            ? 系統採用 sysv 的 /init, 但是沒看到 /etc/inittab
    
    手動執行
        wsl -d Ubuntu-16.04 -u root /etc/init.d/ssh start
    建一個任務在開機的時候自動執行, 至少每次 Windows 重開會自動起來一次. 基於 wsl -t 也不常用, 足夠目前的使用情境了.

重新啟動

    wsl -t Ubuntu-16.04
    下次開 shell 的時候就會自動重啟

解除安裝

在 cmd 裡列出已經安裝的套件清單
    wsl --list

執行 unregister 取消登錄並刪除根檔案系統
    wsl --unregister Ubuntu-16.04

安裝開發基本包

    預設是 64-bit 架構, i386 架構要手動增加
    #sudo dpkg --add-architecture i386
    #sudo apt-get update

    安裝常用 packages
    #sudo apt-get install openssh-client openssh-server subversion git make gcc g++ gawk wget python curl


編譯錯誤訊息與解方

    fatal error: sys/cdefs.h: No such file or directory

        缺乏 libc-dev. 連同 i386 一起安裝
        #sudo apt-get install libc6-dev libc6-dev:i386

    fatal error: openssl/ssl.h: No such file or directory

compilation terminated.

        缺乏 libssl-dev
        #sudo apt-get install libssl-dev libssl-dev:i386

    cannot find -lasound

        缺乏 libasound2
        #sudo apt-get install libasound2-dev libasound2-dev:i386

    cannot find -lstdc++
    cannot find -lgcc_s
    cannot find -lgcc

        需要安裝 lib 包
        #sudo apt-get install g++-multilib gcc-multilib

    Please install ncurses. (Missing libncurses.so or ncurses.h)

        #sudo apt-get install libncurses5-dev

    Please install 'unzip'

        #sudo apt-get install unzip

    fatal: unable to access 'xxx': server certificate verification failed.

        伺服器憑證不被信任.
        下 git 指令之前先執行
            #export GIT_SSL_NO_VERIFY=1

        或永遠不檢查憑證    
            #git config --global http.sslverify false

        或將該站設定為信任. (未完成)

    "__DATE__" might prevent reproducible builds
    "__TIME__" might prevent reproducible builds

        除錯的時候常常要將編譯的日期時間放進去參考, 使用的時候忽略報錯.
        CFLAGS += -Wno-error=date-time

2021/07/13

Ubuntu 20.04 在 Command line 模式設定 static ip

在沒有桌面環境的情況下, 只能用 command line 模式設定網路介面.

Ubuntu 是透過 netplan 來設定.

    #sudo nano /etc/netplan/01-network-manager-all.yaml

以下內容設定 enp8s0
  ip: 192.168.1.140/24
  gw: 192.168.1.1
  dns: 8.8.8.8 1.1.1.1

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: networkd
  ethernets:
    enp8s0:
      addresses: [192.168.1.140/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]


修改完成後可以 apply 立即生效
    # sudo netplan apply

2021/07/09

Geany 搭配 sshfs-win 儲存檔案時出現 Permission denied 的解決方法

Geany

sshfs-win

使用sshfs比samba安全方便. 但是 Geany 存取 sshfs-win 掛載進來的檔案, 在存檔時會抱怨 Permission denied.


解決的方式是撤銷 use_gio_unsafe_file_saving. 操作如下:

1. 拉下【編輯(E)】選單, 點擊【偏好設定(S)】


2. 切換到【各種類型】, 取消勾選 files.use_gio_unsafe_file_saving. 然後套用並確定.



參考資訊:

2021/05/26

debug function for LUCI

 local debug = 0

function dbg_print(...)

if 1 == debug then

local dbg = io.open("/dev/console", "w")

    if dbg then

        dbg:write(os.date("[%H:%M:%S]: "))

        for _, o in ipairs({...}) do

            dbg:write(tostring(o)..'  ')

        end

        dbg:write("\n")

        dbg:close()

    end

end

end