温馨提示×

Ubuntu SSH命令大全及使用技巧

小樊
90
2025-02-16 18:33:48
栏目: 智能运维
Ubuntu服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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命令的基本指南和一些常见技巧。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:Ubuntu SSH端口转发技巧有哪些

0