--- tags: YunNET title: SSH處理方法 --- # SSH處理方法 校內防火牆在SSH密碼打錯太多次及SSH session閒置斷線數次後會把校外IP給擋掉,需要數日才會解除,造成校外辦公及開發困難,這邊提供一些解決方案: ## SSH伺服端關閉自斷斷線 修改伺服端的```/etc/ssh/sshd_config``` 找到```ClientAliveInterval```及```ClientAliveCountMax```並將注釋符號("#")去掉 值改成下圖設定後存檔重啟sshd服務或reboot ``` ClientAliveInterval 30 ClientAliveCountMax 20 ```  ```ClientAliveInterval 30```表示每30分發送測試封包, 然後客戶端響應, 這樣就保持長連接了 ```ClientAliveCountMax 20``` 超過20次客戶端無反應才斷線 ## SSH客戶端公鑰交換 ### Linux客戶端使用者只需照下面指令依照提示操作即可 ```bash= # ssh-keygen # ssh-copy-id ``` ### Windows客戶端使用者在powershell下(Windwos帳戶需全是英文) ```bash= # ssh-keygen ``` 在```C:/Users/<username>/.ssh```底下會產生```id_rsa.pub``` 以記事本打開將內容複製然後ssh到伺服端在```~/.ssh/authorized_keys```尾端貼上後存檔
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up