在Ubuntu系统中,SSH(Secure Shell)是一种用于加密客户端与服务器之间链接的加密协议,提供了一种安全的远程访问和数据传输解决方案。以下是在Ubuntu系统中使用SSH命令的基本方法和一些使用技巧:
安装SSH服务器:
sudo apt update
sudo apt install openssh-server
安装SSH客户端(通常默认已安装):
sudo apt install openssh-client
启动SSH服务:
sudo systemctl start ssh
停止SSH服务:
sudo systemctl stop ssh
重启SSH服务:
sudo systemctl restart ssh
基本连接命令:
ssh username@ip_address
指定端口号连接:
ssh -p port_number username@ip_address
免密登录:
ssh-keygen -t rsa
ssh-copy-id username@ip_address
查看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
列出远程目录内容:
ssh username@hostname 'ls -l /path/to/directory'
创建远程目录:
ssh username@hostname 'mkdir -p /path/to/new_directory'
删除远程文件或目录:
ssh username@hostname 'rm -rf /path/to/file_or_directory'
/etc/ssh/sshd_config
中修改 Port
参数。/etc/ssh/sshd_config
中设置 PermitRootLogin no
。ufw
或其他防火墙工具配置规则。以上信息提供了在Ubuntu系统中使用SSH命令的基本指南和一些常见技巧。