CentOS 7 最簡單安裝 SSH ,使用 SSH 遠端登入 示範

安裝 openssh-server ,也需要 openssh,如果沒有 openssh 會自動詢問是否要安裝
sudo yum install openssh-server

編輯 SSH 設定檔
sudo vi /etc/ssh/sshd_config

把 #Port 22 取消註解,可以把 22 修改為其他 port
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
Port 22

sudo systemctl restart sshd.service

查看 ip:
ip -4 addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet scope host lo
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet brd scope global noprefixroute dynamic ens33
       valid_lft 85537sec preferred_lft 85537sec

使用 ssh 登入:
本次示範是由 windows 11 的指令視窗使用 SSH 連線到 CentOS 7 ,由上面的指令發現 ip 是,port 筆者沒有調整,還是預設的 22 port,使用者名稱為 ruyut:
ssh -p 22 ruyut@
The authenticity of host ' (' can't be established.
ED25519 key fingerprint is SHA256:8T/HNjZj0zw7+2rn4YwI89r5N84JcXXSUdOdST9z//8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '' (ED25519) to the list of known hosts.
ruyut@'s password:
Last login: Sun Sep 24 16:17:22 2023


增加可以連線的 port
sudo firewall-cmd --permanent --zone=public --add-port=22/tcp

sudo firewall-cmd --reload