0%

我想大家都知道SSH是什麼,也很多人應該已經會用SSH Key可以免輸入密碼就可以SSH登入。我想信大家用github應該都會用,但我今天不是要用github 我要用ubuntu 當作SERVER, window 當做client. 其實做法是一樣,github server當作我自己ubuntu server。

很多時候你用github可能一些server上運作可能你不太知道背後的運動是如何,今天可以介由者個範例可以理解更多以真實server

請務必先安裝 openssh 能用

1
sudo apt install openssh-server
  • 公鑰跟私鑰是一組,這樣才可以連線,他們會做連結
    • Private Key 私鑰: 要存在你自己電腦
    • Public Key 私鑰: 要放在本地端要連到Sever。

client建Key

這個方式是最常用的方式,就跟github 一樣,本地端會建private 和public key,然後把public key 傳到 server上面並加入 Server 上的 ~/.ssh/authorized_keys 檔案中。)

以這個範例我本地端(Local/Client)要用SSH遠端到Server端,我需要把我的公鑰(public key)傳到Server這樣私鑰做連線會跟Server公鑰比對,是同一組就會連線。

  • 在 SSH 連線中,Client 會先產生一組公鑰(public key)和私鑰(private key)。
  • 公鑰會放到 Server 上,而私鑰只保留在 Client。

當 Client 嘗試連線時,會使用私鑰(private key)來進行驗證,而Server 會利用它儲存的公鑰來驗證 Client 的私鑰是否正確,確認是同一對金鑰後,即可成功連線,我下面我教如何做到。

Read more »

今天想分享我用 Rassberry PI5 架 ACS Server,如果你知道 ACS Server 是甚麼,可以看我如何架。ACS Auto Configure server,類似遠端的工具可以看到你的通訊產品的狀況如上線時間,reboot,更新 FW 等等

Note:

For English Note please refer to my github note link

Raspberry PI Model

Check Ubuntu Version

1
lsb_release -a

Check Kernel

1
uname -ar

check Raspberry Model

1
2
3
cat /proc/device-tree/model
#or
cat /proc/cpuinfo | grep 'Model'
Read more »

今天我想要分享用 UBUNTU 架設 ngix http server,同時我也會用 docker 方式安裝。

NGIX Setup ubuntu

Step1. Install Nginx

1
sudo apt install nginx -y

Step2. show nginx status

Verify Nginx is Running show statusd

1
sudo systemctl status nginx

Step3: Firewall setting

1
2
sudo ufw allow 'Nginx HTTP'
sudo ufw reload
Read more »

今天想分享如何用 python 轉 exe,也就是說如果你把你的 python 檔案轉成 exe 放在其他電腦就可以執行。這個好處就是你不用在其他電腦安裝 python 或其他 library,就可以用。

Install Pyinstaller

這有很多方法和套件可以用,但我都用 pyinstaller

安裝 pyinstaller: pip install pyinstaller

pyinstaller 用法

  • 基本用法
1
2
#simple convert
pyinstaller your_script.py
  • Adding Icons:

可以在下面連結下載 ico 也可以用,下載會是 .png檔案,需要轉成 .ico

1
pyinstaller --onefile --icon=myicon.ico your_script.py
Read more »

This is a note for change your python version in jupyter Notebook. 今天想要分享如何換在 jupyter Notebook 換不同 python 般本

Please Install latest python for example python 3.13 which is the latest version, if you are going to switch to python 3.13. You don’t have to install latest version, it’s because I want to switch to python3.13, please be noted.

請務必先安裝最新的 python 3.13,由於我要切換到 python 3.13,因此必須要先安裝 python 3.13。

Changing python version in jupyter

Step changing python version

Step1: Install package

  • Install Jupyter (optional): pip install jupyter

  • Install ipkernel: pip install ipykernel

You can also install under virtual environment

1
2
3
4
5
6
7
#1. create virtual env with conda
#syntax: conda create -n <virtual env name> python=3.13
conda create -n py313 python=3.13


#2. Activate the new environment
conda activate py313

you can also use conda command conda env list to list virtual env.

Read more »

今天我想分享關於目錄和檔案相關範例,如重新立名,出檔案,我會用很多方式呈現出來。

List current directory 目錄利出檔案

list your file in current directory 目錄列出檔案

我們常在 linux 和 window 都會用 ‵ls‵ 或 ‵dir‵ 來列出我們目錄底下所有檔案。 可以用 os.listdir() 就可以利出所有目錄和檔案

目前目錄下: os.listdir()

指定位置: os.listdir(path)

1
2
3
import os
for file in os.listdir():
print(file)

output:

1
2
3
4
5
6
7
8
counter.py
elogfile
elogfile.txt
elogfile2
elogfile2.txt
list_file.py
logchecking.py
logchecking_rename.py

filter specific file or file type 篩選檔名

有幾個方式可以用,如果要指定檔案類型 我們可以用: startswith()endswith().

Read more »

This exercise is to show you how to count your string occurrences, or how many duplicated value. 我想分享如何找估重複文字次數。

iterate through list, and store in dictionary

[方法一] 基本 loop 把它存在 dictionary

output: {'James': 1, 'Kelly': 2, 'Sammie': 1

1
2
3
4
5
6
7
8
9
10
listofName=['James','Kelly', 'Sammie', 'Kelly']
dictcollect={}
for name in listofName:
if name in dictcollect:
dictcollect[name]+=1

else:
dictcollect[name]=1
print(dictcollect)

其實可以寫成更簡短方式,其實跟上面方式一樣

1
2
3
4
5
listofName=['James','Kelly', 'Sammie', 'Kelly']
dictcollect={}
for name in listofName:
dictcollect[name]=dictcollect.get(name,0)+1
print(dictcollect)

如果沒出現就離開,出現就會+1,也可以這樣做 1+dictcollect.get(name,0)

dictcollect.get(name, 0) checks if the name already exists as a key in the dictionary.
If it exists, the current count is retrieved.
If it doesn’t exist, 0 is returned.

[方法二] collection 裡面的 count

Read more »

Understanding Function Annotations ->:

Today I would like to share when we see an arrow or colon on function, basically there’s a term Function Annotation. I see some turtorial and see many developer beeen using it, and went and research on it.

You can think it’s just a comment, nothing else. It to tell people about your code expectation, like data type or return value. So let me show you some examples, and you will see the arrow or colon doesn’t mean anything, it just to tell people what this variable mean.

1
2
3
4
5
6
def velocity(s: 'in miles', t: 'in hours') ->'mph':
return s/t

velocity(4,5) # 0.8

print(velocity.__annotations__)

output:

{'s': 'in miles', 't': 'in hours', 'return': 'mph'}

from above example it just to tell user s is in mile, t is in hours, and return mph

You will see many people use like this to define datatype:

1
2
3
4
5
def calculate(a: int, b: int)-> int:
return a+b
result= calculate(4,5)
print(calculate.__annotations__)
# {'a': <class 'int'>, 'b': <class 'int'>, 'return': <class 'int'>}

overall it just to tell people what the code expectation is or are.

Read more »

今天來分享如何應用 virtual env 來提高工作環境等效率。如果使用 python library 我想信很多時候都會用 pip 來安裝他的 library 等 module。如果某些套件版本跟你專安不 match 造成無法 code 無法運行怎麼呢?這時你只有降版本,也就是可能要先移除再安特殊版本。另一種方式就是建立一個 virtual env 也就是類似虛擬環境,這裡可以安裝任何 package or library 跟主環境分離不會有相關。

我覺得這個很好用,如果你原本主環境安裝太多 library 你有時還要 debug,你可以一開就建立在乾淨環境,再安裝你要安裝個 library or module 等 package。

可以用這兩終方式建立 virtualenv,如:

  • virtualenv : 需要安裝套件
  • venv:內建就有無須安裝特建

venv

Syntax: python -m venv <my_env_name>
EX: python -m venv venv

  • 如何用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#create new directory
mkdir newproject
cd newproject

#create virtual env
py -m venv env_apitest

#activate

.\.env_apitest\Scripts\activate #for window
source .env_apitest\Scripts\activate #for linux or mac

#deactivate
deactivate

# upgrade python version
python -m venv /path/to/venv --upgrade

virtualenv

Read more »

今天想要來分享如何在 window 上面設定像 Linux 或 Mac 相關花麗等冬端機 terminal,和以些 linux 不錯的指令。如果你們有用過 Linux,在用 window 很不習慣,尤其是指令。今天想分享如何用 Oh-my-posh 在 window 上面可以跟 Linux 的 Oh-my-zsh 有依樣效果。Window 是用在 powershell 上,他有支援很多 shell bash zsh powershell fish等等。我有寫一篇比較完整,在Medium 因此今天會寫簡短方法。

安裝工具

軟體安裝服務比較

如果你有用過 Ubuntu 都會看到大家常用 apt-get install 這命令,這個就是我稱為的安裝服務工具。他可以很快速幫助你要安裝個套件。我今天要介紹 3 個,但我會以 winget 優先用,如果 winget 沒有套件再選其他兩個。winget 是微軟開發因此我才會優先用他。我會盡可能不去商店下載。

正常來說 winget 預設鏡安裝了,如果你是 win10 都會安裝,如果指令找不到就用下方的方法。如果 winget有,那把 scoop安裝,Chocolatey就看你要挨裝嗎,我目前沒用到。

  • Winget
    先到這裡下載 ,檔案會是 Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle然後用這個指令安裝:
1
2
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Add -AppPackage
1
2
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
Read more »