mirror of
https://github.com/damp11113/PyserSSH.git
synced 2025-04-28 06:58:12 +00:00
Created [Thai] Home (markdown)
parent
1bbe96f9f8
commit
2aefc79468
66
[Thai]-Home.md
Normal file
66
[Thai]-Home.md
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
วันนี้ผมจะมาแนะนำ python library ตัวหนึ่งที่ผมทำขึ้นมาเพื่อ remote มาทำคำสั่งกับ code ของเราผ่าน SSH นั้นเอง
|
||||||
|
# อะไรคือ PyserSSH
|
||||||
|
PyserSSH คือ library python ที่ทำมาเพื่อ ควบคุมโค้ดของคุณจากระยะไกลด้วย SSH Client
|
||||||
|
จุดมุ่งหมายคือ SSH server ที่สามารถเขียนสคริปต์ได้
|
||||||
|
# ความสามารถหลักๆ
|
||||||
|
- Shell
|
||||||
|
- SFTP
|
||||||
|
# Install
|
||||||
|
ลงจาก pypi
|
||||||
|
```
|
||||||
|
pip install PyserSSH
|
||||||
|
```
|
||||||
|
ลงจาก github (อาจใหม่กว่า ลงจาก pypi)
|
||||||
|
```
|
||||||
|
pip install git+https://github.com/damp11113/PyserSSH.git
|
||||||
|
```
|
||||||
|
## library ที่ไม่จำเป็น แต่อยู่ใน library นี้
|
||||||
|
- damp11113-library (https://github.com/damp11113/damp11113-library)
|
||||||
|
|
||||||
|
# วิธีการ generate private key มี 2 วิธี
|
||||||
|
private key เป็นสิ่งสําคัญสําหรับเปิด SSH server เพื่อการแสดงตัวตนของผู้ใช้
|
||||||
|
## 1. ใช้ ssh-keygen ของ openssh
|
||||||
|
รูปแบบคำสั่ง
|
||||||
|
```
|
||||||
|
ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa | rsa1] [-N new_passphrase] [-C comment] [-f output_keyfile]
|
||||||
|
```
|
||||||
|
การนำไปใช้
|
||||||
|
```
|
||||||
|
ssh-keygen -m PEM -t rsa -f private_key.pem
|
||||||
|
```
|
||||||
|
## 2. ใช้ keygen online
|
||||||
|
แนะนำเป็น https://8gwifi.org/sshfunctions.jsp
|
||||||
|
# Code ตัวอย่าง
|
||||||
|
```py
|
||||||
|
import os
|
||||||
|
from PyserSSH import Server, Send, AccountManager
|
||||||
|
|
||||||
|
useraccount = AccountManager()
|
||||||
|
useraccount.add_account("admin", "")
|
||||||
|
|
||||||
|
ssh = Server(useraccount)
|
||||||
|
|
||||||
|
@ssh.on_user("command")
|
||||||
|
def command(channel, command: str, client):
|
||||||
|
if command == "hello":
|
||||||
|
Send(channel, "world!")
|
||||||
|
|
||||||
|
ssh.run(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'private_key.pem'))
|
||||||
|
```
|
||||||
|
การทำงานของ code ตัวอย่าง
|
||||||
|
เมื่อคุณเชื่มต่อไปยัง `ssh admin@localhost -p 2222` (ถ้าถามรหัสผ่าน ก็ไม่ต้องพิมพ์อะไรลงไปแล้วกด enter เลย)
|
||||||
|
ถ้าคุณพิมพ์ `Hello` server จะตอบกลับว่า `world!`
|
||||||
|
|
||||||
|
# ตัวอย่าง เพิ่มเติม
|
||||||
|
https://github.com/damp11113/PyserSSH/assets/64675096/49bef3e2-3b15-4b64-b88e-3ca84a955de7
|
||||||
|
|
||||||
|
สามารถดูได้ที่ [server.py](https://github.com/damp11113/PyserSSH/blob/main/demo/server.py)
|
||||||
|
|
||||||
|
library นี่ผมใช้ เวลาไป ศึกษาและพัฒนา ประมาณ 6 เดือนกว่าจะได้แบบนี้จึงมาแชร์เพื่อให้รู่ว่ามี library แบบนี้อยู่ด้วย
|
||||||
|
library นี้เคยอยู่ใน damp11113-library แต่อาจไม่สะดวกสำหรับบางคนเพราะมีการใช้ dependencies ที่มากและโหลดนาน จึงแยกออกมาเป็น library เดียว
|
||||||
|
|
||||||
|
Pypi: https://pypi.org/project/PyserSSH/
|
||||||
|
|
||||||
|
Github: https://github.com/damp11113/PyserSSH/
|
||||||
|
|
||||||
|
Issues: https://github.com/damp11113/PyserSSH/issues
|
Loading…
x
Reference in New Issue
Block a user