安裝環境

SSH Server: Ubuntu 22.04
SSH Client: Windows 11

安裝 SSH Server

1
sudo apt install openssh-server

設定使用密碼登入

使用 vi 開啟 sshd_config

1
sudo vi /etc/ssh/sshd_config

修改伺服器 sshd_config

1
PasswordAuthentication yes

vi 離開文件方法

先按 Esc

  • :q: 沒有做修改離開
  • :wq: 保存並離開
  • :q!: 不保存就離開

重新啟動 SSH 伺服器

1
service sshd restart

取得伺服器 IP

使用 ifconfig 查看 IP

若沒安裝時使用以下指令安裝

1
2
sudo apt update
sudo apt install net-tools

設定免密碼登入

客戶端產生 SSH Key

1
ssh-keygen

從 Client 複製 public key 到 Server

1
2
cd %USERPROFILE%\.ssh
scp id_rsa.pub SERVER_USERNAME@SERVER_HOST:~/.ssh

伺服器端設定 SSH Key

1
2
cd ~/.ssh
cat id_rsa.pub >> authorized_keys

修改伺服器 sshd_config

1
2
PubkeyAuthentication yes
PasswordAuthentication no

重新啟動 SSH 伺服器

1
service sshd restart