顯示具有 startup 標籤的文章。 顯示所有文章
顯示具有 startup 標籤的文章。 顯示所有文章

2023年9月7日 星期四

Windows 開發筆記 - 開機自動啟動 SSH Reverse Tunnel / autossh @ Windows 11, cygwin

視窗鍵 + R 輸入 shell:startup

想說要善加利用 Windows 筆電,就想到把它規劃成算力單位後,以及思考如何自動化叫他做事。在資安角度上就可採用 SSH Reverse Tunnel 方案,讓筆電開機啟動後,建立一個連線到指定的機器候命。如此,在 Windows 筆上安裝了一些服務後,就可以用遠端 Port Forwarding 的方式存取到。

首先,要先找到 autossh 這種用法,不然單建立一個 ssh 掛了很麻煩的。雖然有一些 github 的可挑,但整體上要找一個夠信任的來源,最後選擇知名的 cygwin ,就順便安裝 autossh, tmux, vim, wget, lftp, git, zip, unzip 等,如此 autossh.exe 就搞定,位置在 C:\cygwin64\bin\autossh.exe

之前的文章已提到,我在 Windows 11 下已啟用 OpenSSH server 了,那我可以測試把 openssh server 服務建立反向的連線(須留意 cygwin 認定的使用者家目錄跟 Windows PowerShell 的不一樣,需要先建立好 keypair 等資料)

C:\cygwin64\bin\autossh.exe -M 0 -N -R 10022:localhost:22 ServerUser@RemotServer

如此,在指定的機器(RemoteServer)上,就可以測試連線:

$ telnet localhost 10022
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
SSH-2.0-OpenSSH_for_Windows_8.6
^C^C
Connection closed by foreign host.

對於 cygwin 方面,目前採用 Windows 內建的 OpenSSH server 方案,連入後是 Windows Powershell 環境,若想切換到 cygwin ,可以多打一下:

Microsoft Windows [版本 10.0.22621.2215]

(c) Microsoft Corporation. 著作權所有,並保留一切權利。


user@WINDOWS-DESKTOP C:\Users\user>c:\cygwin64\Cygwin.bat


user@windows-desktop ~

$ 


對於 cygwin 用法,正規的安裝軟體還是透過原本的 setup.exe 去擴充,然而,可以去下載 github.com/transcode-open/apt-cyg 來使用,他可以提供一些便利的 command line 安裝套件的方式(但實務上不幸踩過失敗),當作一個備用方式:

user@windows-desktop ~

$ curl -s https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg


user@windows-desktop ~

$ chmod 700 ./apt-cyg 


user@windows-desktop ~

$ ./apt-cyg 

NAME

  apt-cyg - package manager utility


SYNOPSIS

  apt-cyg [operation] [options] [targets]


DESCRIPTION

  apt-cyg is a package management utility that tracks installed packages on a   

  Cygwin system. Invoking apt-cyg involves specifying an operation with any     

  potential options and targets to operate on. A target is usually a package    

  name, file name, URL, or a search string. Targets can be provided as command  

  line arguments.


OPERATIONS

  install

    Install package(s).


  remove

    Remove package(s) from the system.


  update

    Download a fresh copy of the master package list (setup.ini) from the       

    server defined in setup.rc.


  download

    Retrieve package(s) from the server, but do not install/upgrade anything.   


  show

    Display information on given package(s).


  depends

    Produce a dependency tree for a package.


  rdepends

    Produce a tree of packages that depend on the named package.


  list

    Search each locally-installed package for names that match regexp. If no    

    package names are provided in the command line, all installed packages will 

    be queried.


  listall

    This will search each package in the master package list (setup.ini) for    

    names that match regexp.


  category

    Display all packages that are members of a named category.


  listfiles

    List all files owned by a given package. Multiple packages can be specified 

    on the command line.


  search

    Search for downloaded packages that own the specified file(s). The path can 

    be relative or absolute, and one or more files can be specified.


  searchall

    Search cygwin.com to retrieve file information about packages. The provided 

    target is considered to be a filename and searchall will return the

    package(s) which contain this file.


  mirror

    Set the mirror; a full URL to a location where the database, packages, and  

    signatures for this repository can be found. If no URL is provided, display 

    current mirror.


  cache

    Set the package cache directory. If a file is not found in cache directory, 

    it will be downloaded. Unix and Windows forms are accepted, as well as      

    absolute or regular paths. If no directory is provided, display current     

    cache.


OPTIONS

  --nodeps

    Specify this option to skip all dependency checks.


  --version

    Display version and exit.


下一步回歸到正題 - 開機自動執行,則是可以參考微軟官方文件 - 新增的應用程式以在 Windows 10 啟動時自動執行。此例在 Windows 11 上,透過 視窗鍵+R 執行 shell:startup 可快速開啟對應的目錄位置 ( %HOME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup ),只需在此目錄添加幾個 bat 檔案,開啟就會幫我運行這指令了,如:

00_ssh-reverse-tunnel_openssh-server.bat

內容:

C:\cygwin64\bin\autossh.exe -M 0 -N -R 10022:localhost:22 ServerUser@RemotServer

開啟後,他會佔一個小視窗。由於那台筆電本身就是閒置的,所以佔著小視窗反而更好觀測 autossh 運作是否正常

收工!

2015年4月14日 星期二

與大老闆有約

最近跟幾位大老闆聊天,也回顧起前老闆的互動,有些經驗真的是自己親身體驗的,所以特別有感觸,有些則是像看著書看電影,不如聽人親口說出來:

  • 所謂的 startup 是個生活的方式,若是以音樂圈舉例,大概出門都想比個 rock 手勢 XD 整體上就一種工作生活的模式,並非 startup 就過得比較好、比較爽。
  • 有錢出錢,沒錢想出技術、時間,但是,所有的技術股本質上都是有對等的錢,有些工程師會想拿很大比例的股票,用的是技術股而非自己的錢去買,但技術股一開始規劃太多會讓投資人不敢投資。而技術股本身就是有等值的金錢價值,無論有沒有成功上市還是一張壁紙,在當下就是有對等價值。所以,有機會拿到技術股時,要想想這些股票其實是 co-founder 的錢,他們為了打造團隊忍痛分出來的
  • 有些新創會讓你把年薪的幾趴用技術股,但真正有價值的公司,股票是很貴的,能給錢就給錢,不會想給技術股,因為通常每一輪增資時,股價是飛快地成長,小則幾十倍,大則百倍、千倍 XD 你想想 co-founder 一開始手上的 1 萬,經過一輪變成一百萬時,你覺得他會想給你股票嗎?
  • 團隊永遠優於題目,對天使來說,投資的是你的團隊,而不是你的題目
  • 搞 startup 的方向有很多種,有人想要長期持有,也有人想要短期翻百倍、千倍脫手,並沒有不好之處
  • 公司願意給人高薪時,某個角度是資金狀況達到一個水準,某個角度是為了打造明星戰隊,好讓下一輪募資有更佳的價值,其實都是好事。當公司給高薪卻不給股票時,有時不要太貪心,至少拿到高薪了!換個角度來說,這可是 co-founder 早期的投資成果呢!不然你連高薪的機會都沒有。
  • 對天使來說,大概投資 25 間才會有一間成功,若早期報酬率有25倍,那只是剛好打平而已

至於進 startup 到底要幹嘛?基本上選擇當 co-founder 後,已經是一條不歸路了,無論成功或失敗,自身都是很有價值的,要記得最重要的永遠是人脈圈,練人脈等同練信任感,失敗並不會怎樣,至少天使會知道你下次不會再犯一樣的錯了。

不過,有一個非常現實的問題...連續創業可以創造價值沒錯,但是 co-founder 的股份初期再怎樣還是用等價的錢打造的,所以想連續創業...還是要有一些錢錢才可以進行。別忘了 co-founder 還是要盡量保持大量持股,因為每一輪的角色會稀釋,甚至最後要找專業經理人時,必須自己拿股份出來吸引專業經理人。這筆股份/錢,我想任何投資人都不想出的。

最後一提,若30歲了加入公司的角度還是想著練功,那永遠都無法跳脫員工的角度。30歲這個年紀,已經該去指揮別人了。