SSH(Secure Shell)是一种用于加密客户端与服务器之间链接的加密协议,客户端与服务器的每一次交互都被加密。以下是在Ubuntu系统中使用SSH命令的基本方法和一些使用技巧:
安装SSH
- 安装SSH服务器:
sudo apt update sudo apt install openssh-server
- 安装SSH客户端(通常默认已安装):
sudo apt install openssh-client
启动和停止SSH服务
- 启动SSH服务:
sudo systemctl start ssh
- 停止SSH服务:
sudo systemctl stop ssh
- 重启SSH服务:
sudo systemctl restart ssh
连接到SSH服务器
- 基本连接命令:
ssh username@ip_address
- 指定端口号连接:
ssh -p port_number username@ip_address
-
免密登录:
-
生成密钥对:
ssh-keygen -t rsa
- 将公钥复制到远程服务器:
ssh-copy-id username@ip_address
常用SSH命令使用技巧
- 查看SSH服务状态:
sudo systemctl status ssh
- 配置防火墙允许SSH连接:
sudo ufw allow ssh
- 从远程服务器复制文件到本地:
scp username@ip_address:/path/to/remote/file /path/to/local/destination
- 从本地复制文件到远程服务器:
scp /path/to/local/file username@ip_address:/path/to/remote/destination
- 断开SSH连接:
exit
以上信息提供了在Ubuntu系统中使用SSH命令的基本指南和一些常见技巧。