# ssh 不用輸入密碼 and 次數限制 ## Lab Computer ```bash rsync -avzP -e "ssh -p 2024" --exclude 'home/sucryan/Desktop/RL/Lab4/src/log/' ~/Desktop/RL/Lab4 aaslab4080@140.113.:~/YuChen/ ``` ## ssh使用金鑰登入 ### 創建 效果::star:==每次登入的時候就不用重新輸入密碼!==:star: - 首先先在cmd(windows)/terminal(macOS)輸入(記得換成你的email) ```bash= ssh-keygen -t rsa -b 4096 -C "your_email@example.com" ``` #### windows - 點開git bash,沒有的話可以去[這裡](https://gitforwindows.org/)下載  - 輸入以下內容 ```bash= ssh-copy-id username@remote_host ``` #### macOS - 直接點開terminal  - 輸入以下內容(記得換成你的username跟ip) ```bash= ssh-copy-id username@remote_host ``` ```bash! # 本地端連線ssh端之port可使用localhost ssh -L 8888:localhost:8888 sucryan@140.113.127.231 ``` ### error handle #### REMOTE HOST IDENTIFICATION HAS CHANGED!  - 如果你之前有用過了,然後你可能重灌電腦之類的,那你可能就會遇到這個問題,那怎麼解決呢? - 先把你之前的紀錄抹掉(填你自己的ip) ```bash! ssh-keygen -R {ip} ``` - 接下來再重新輸入就沒問題了! ```bash! ssh-copy-id username@remote_host ``` ## 擋掉ssh暴力密碼破解 [可參考用的medium](https://medium.com/@jieshiun/%E5%A6%82%E4%BD%95%E5%9C%A8-ubuntu-22-04-%E4%BD%BF%E7%94%A8-fail2ban-%E4%BE%86%E4%BF%9D%E8%AD%B7-nginx-64a8bd2a1ce3) - 使用上其實很簡單,基本上只要載下來 ```bash! sudo apt install fail2ban -y ``` - enable然後start ```bash! sudo systemctl enable fail2ban sudo systemctl start fail2ban ``` - 然後跑這個,他有反應代表他現在就有在工作了 ```bash! sudo fail2ban-client status sshd ```  - 然後只打status的話就可以看你現在會被fail2ban保護的服務有什麼 ```bash! sudo fail2ban-client status ```  - 然後你也可以看他的max_tries ```bash! sudo fail2ban-client get sshd maxretry ```  - 最後如果你想要調整你的jail.conf可以參考最上面那個網站,他講得很詳細,但是因為其實預設的就已經可以做到擋掉暴力破解ssh的功能了,所以就不詳述。
×
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