vault backup: 2025-08-14 23:04:04
Affected files: 21.01. OS/21.01. Linux/ssh.md
This commit is contained in:
@@ -6,7 +6,42 @@ time: 22:51:46
|
||||
description:
|
||||
---
|
||||
|
||||
## 免登入
|
||||
要登入那台記得要先安裝 SSH server:
|
||||
```
|
||||
sudo apt install -y openssh-server
|
||||
```
|
||||
|
||||
### 透過 ssh-copy-id
|
||||
```shell
|
||||
ssh-copy-id -i ~/.ssh/id_rsa.pub awin@192.168.1.99
|
||||
```
|
||||
|
||||
### 直接將公鑰資料複製到 server 的 ~/.ssh/authorized_keys 中
|
||||
先記下剛剛產生的公鑰資料
|
||||
```
|
||||
cat ~/.ssh/ubuntu_id_rsa.pub
|
||||
```
|
||||
|
||||
會顯示公鑰資料,把它複製下來
|
||||
```
|
||||
ssh-rsa AAAAxxxxxxx xxxx@demo.com
|
||||
```
|
||||
|
||||
|
||||
連線到伺服器上後,將公鑰資料複製到 `~/.ssh/authorized_keys` 中 (下面指令的 public_key_string 要換成剛剛複製的公鑰資料)
|
||||
|
||||
如果該檔案已經存在就將資料新增到新的一行,如果不在就自己創建一個
|
||||
|
||||
```
|
||||
echo "public_key_string" >> ~/.ssh/authorized_keys
|
||||
```
|
||||
|
||||
假如剛剛自己是建立一個新的檔案,因為安全性的關係要改變 permission
|
||||
輸入以下兩個指令 (username需要換成自己的帳號)
|
||||
```
|
||||
chmod -R go= ~/.ssh
|
||||
chown -R username:username ~/.ssh
|
||||
```
|
||||
|
||||
# 參考來源
|
||||
Reference in New Issue
Block a user