sudo apt update && sudo apt install openssh-client
sudo apt update && sudo apt install openssh-server
sudo systemctl status ssh
查看状态。/etc/ssh/sshd_config
,找到 #Port 22
,改为 Port 2222
,并重启服务:sudo systemctl restart ssh
sshd_config
中设置 PermitRootLogin no
,重启服务。ssh-keygen -t rsa -b 4096
(默认保存在 ~/.ssh/
)ssh-copy-id user@remote_ip
。ssh username@remote_ip -p 端口号
(默认端口22可省略)ssh user@192.168.1.100 -p 2222
~/.ssh/authorized_keys
,直接使用 ssh username@remote_ip
即可。scp local_file user@remote_ip:/path/
scp user@remote_ip:/path/file local_path
~/.ssh/config
,添加:Host myserver HostName remote_ip User user Port 2222 IdentityFile ~/.ssh/my_key
之后可直接用 ssh myserver
连接。~/.ssh
目录权限为700,authorized_keys
文件权限为600。