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