# W2 (2023/09/19) ## 終端機操作: * Ctl + a 移到最前面 * Ctl + e 移到最後面 在server上 0.0.0.0 表示anyinterface (ex:有無限跟有限網卡各一張,client進入server時,任意張都能進入) ## 遠端登入失敗 1. 檢查 server是否在運作 `systemctl status sshd` ![](https://hackmd.io/_uploads/SJtKn3IJa.png) 2. 檢查 port number 是否在正常的位置上 (ssh 在 22 port, http 在 80port) `netstat -tulnp | grep sshd` ![](https://hackmd.io/_uploads/ByvDh2L1T.png) 3. 檢查 selinux `getenforce` (修改 /etc/selinux/config) ![](https://hackmd.io/_uploads/B1MrhhIJT.png) 4. 檢查 firewall `firewalld` (關防火牆) ![](https://hackmd.io/_uploads/Sy3G3nLJ6.png) 5. 檢查虛擬機設定 (IP設定是否一致) ![](https://hackmd.io/_uploads/H1CYphL16.png) * Putty & WinSCP 登入虛擬機 ![](https://hackmd.io/_uploads/S1h1W68yp.png) ## Linux 機器登入機器 ### 前置 1. 編輯 /etc/hosts ![](https://hackmd.io/_uploads/B1OnW6Iy6.png) 2. 網域名 ping ![](https://hackmd.io/_uploads/rJC1fTUkT.png) 3. 登入 ![](https://hackmd.io/_uploads/Byrzz6U1p.png) ## 無密碼登入 1. 產生公私鑰 ![key](https://hackmd.io/_uploads/SJz4m6UJp.png) 2. 檢查 (.pub 為公鑰) ![check_key](https://hackmd.io/_uploads/HyQLXpUyT.png) 3. 將密碼送到另一台機器 ![send_passwd](https://hackmd.io/_uploads/S1PnmTUyp.png) 4. 登入測試 ![login_test](https://hackmd.io/_uploads/B1WR7aIy6.png) ## SCP * 機器跟機器之間檔案的拷貝: `scp 檔案位置 帳號@機器:複製位置` ![check&copy](https://hackmd.io/_uploads/BkiEv6UJa.png) * 複製資料夾: `scp -r /testdir root@vm2:/tmp` **-r:遞迴 用意為把資料夾內檔案全部複製** ![](https://hackmd.io/_uploads/ByOQGRI1p.png) ## 修改 ssh port 1. 在 /etc/ssh/sshd_config , 修改`# port 22` ex: port 2222 ![](https://hackmd.io/_uploads/ryp3_08ka.png) 2. `systemctl restart sshd` 重啟 ssh-server **可以用`systemctl status sshd` 或 `netstat -tunlp | grep ssh` 查看** 3. `ssh root@vm1 -p 2222` 連線時需加上 port ![change_port](https://hackmd.io/_uploads/HkglOCLya.png) :::info 如果無法連線的話,依照**遠端登入失敗**的流程檢查 :::