Ssh
打开
sudo apt update
sudo apt install openssh-server
启动
sudo systemctl start ssh
自动开启
sudo systemctl enable ssh
状态
sudo systemctl status ssh
防火墙
sudo ufw allow ssh
#或者
sudo ufw allow 22/tcp
配置
/etc/ssh/sshd_config
- Port 2222
- PasswordAuthentication yes
连接
ssh user@192.168.1.100 -p 2222
密钥(可选)
如果已经在本地机器上生成了SSH密钥对,并且将公钥添加到了目标服务器的 ~/.ssh/authorized_keys 文件中,你可以使用密钥认证而不需要输入密码。
#生成SSH密钥对
ssh-keygen -t rsa -b 4096
#将公钥复制到目标服务器
ssh-copy-id -i ~/.ssh/id_rsa.pub user@192.168.1.100
#使用密钥连接
ssh user@192.168.1.100