在 Ubuntu 上通过 SSH 连接远程服务器,一般分客户端连接和服务端配置两部分。下面按常见使用场景说明:
sudo apt update
sudo apt install openssh-client
ssh 用户名@服务器IP
示例:
ssh root@192.168.1.100
如果是非默认端口(如 2222):
ssh -p 2222 user@192.168.1.100
会提示:
Are you sure you want to continue connecting (yes/no)?
输入 yes 回车,然后输入密码即可。
ssh-keygen
一路回车即可(默认生成在 ~/.ssh/id_rsa)
ssh-copy-id user@服务器IP
ssh user@服务器IP
无需输入密码。
sudo apt update
sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh
sudo systemctl status ssh
ip a
sudo ufw allow 22
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
编辑:
sudo nano /etc/ssh/sshd_config
修改:
Port 2222
重启:
sudo systemctl restart ssh
如果你是想:
可以告诉我具体场景,我给你更针对性的步骤。