SSH(Secure Shell)是設置一種網(wǎng)絡(luò )協(xié)議,用于在不安全的遠程網(wǎng)??絡(luò )環(huán)境中提供安全的遠程登錄服務(wù),C??entOS 系統默認支持 SSH 服務(wù),設置??用戶(hù)可以通過(guò) SSH 客戶(hù)端進(jìn)行遠程登錄,遠程本文將詳細介紹如何在 CentOS 系統中設置遠程 SSH 登錄。設置
1、遠程確保系統已經(jīng)更新到最新版本,設置執行以下命令:
sudo yum update
2、遠程安裝 open=""SSH 服務(wù)器軟件包,設置執行以下命令:
sudo yumヽ(′▽?zhuān)?ノ install open=""ssh-server
3、遠程啟動(dòng) open='open'SSH 服務(wù)并設置開(kāi)機自啟,設置執行以下命令:
sudo systemctl start sshdsudo systemc??tl enable sshd4、遠程查看 open='open'SSH 服務(wù)狀態(tài),設置執行以下命令:
sudo systemctl sta(′?_?`)tus sshd為了允許外部設備通過(guò) SSH 連接到 CentOS 系統,遠程需要開(kāi)放 SSH 端口,設置執行以下命令:
sudo fi(′?_?`)rewall-cmd --permanent --add-service=sshsudo firewall-cmd --reload
1、在本地計算機上生成 SSH 密鑰對,ヽ(′▽?zhuān)?ノ如果已經(jīng)有密鑰對,可以跳過(guò)此??步驟,執行以下命令:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
按提示操作,可以選擇(′?_?`)默認路(′_`)徑和文件名,也可以(yi)自定義,這將在指定路徑下生成一個(gè)私鑰文件(默認為 ~/.ssh/id_rsa)和一個(gè)公鑰文件(默認為 ~/.ssh/id_rsa.pub)。
2、將公鑰文??件內容添加到遠程服務(wù)器的 ~/.ssh/authorized_keys 文件中,可以(′Д` )使用以下命令將公鑰復制到遠程服務(wù)器:
ssh-cop??y-id user@remote_host
user 是遠程服務(wù)器上的用戶(hù)名,remote_host 是遠程服務(wù)器的 IP 地址或域名,輸入密碼后,公鑰將被自動(dòng)添加到遠程服務(wù)器的 ~/.ssh/authorized_keys 文件中,如果沒(méi)有安裝 ssh-copy-id,可以手動(dòng)將公鑰內容追加到遠程服務(wù)器的 ~/.ssh/authorized_keys 文件??中。
1、從本地計算機嘗試使用 SSH 客戶(hù)端登錄遠(???)程服務(wù)器,執行以下命令:
ssh user@??remote_host
2、如果一切??正常,將會(huì )看到類(lèi)似以下的輸出信??息:
Last login: Mon Jan _2 15:30:00(╯°□°)╯ UTC 2022 from your_local_ip_addr??ess on?? remote_host by user@P(′▽?zhuān)?)C name with Linux (x86_64) using X11 forwarding; type 'help' or 'h' for help. user@(′_`)remote_host logged in on remote host. Welcome! You have successfully authenticated to the remo??te system. If this is the first time you log in, please run "passwd" and follow the ins??tructions to set your password. Otherwise, you can continue using your exist(′;д;`)ing password. If you forget your?? password, use "passwd" to change it. Bye! user@remote_host has finished logging in at Mon Jan _2 15:30(??-)?:00 UTC 2022. user has(′▽?zhuān)?) been granted access to your_remote_home directory. Type "exit" when you're done. user(′?`*) has finishe??d logging out of your_remote_session at Mon Jan _2 15:30:00 UTC 2022. exit|logout|quit|??sync|bye|exit|lo(′ω`*)goff|signout are valid commands for quitting a shell session. Type "help" for more information about these commands or type "h" for help wi??th a specific command. Please enter yo(′?`*)ur command now. [root@remote_host ~]
至此,已經(jīng)成功設置了遠程 SSH 登錄,如有其他問(wèn)題,請參考下面的相關(guān)問(wèn)題與解答欄目。