# 介绍

安全外壳协议(Secure Shell Protocol,简称 SSH)是一种加密的网络传输协议,可在不安全的网络中为网络服务提供安全的传输环境。SSH 通过在网络中建立安全隧道来实现 SSH 客户端与服务器之间的连接。SSH 最常见的用途是远程登录系统,人们通常利用 SSH 来传输命令行界面和远程执行命令。

# 更新 Ubuntu

终端执行以下命令

sudo apt update && sudo apt upgrade -y

# 安装 OpenSSH

终端执行以下命令

sudo apt install openssh-server -y

使用 systemctl 开启 SSH 服务

sudo systemctl enable --now ssh

查看服务运行状态

sudo systemctl enable --now ssh

查看连接状态

sudo ss -lt

# 连接 SSH

发起连接终端执行以下命令

ssh username@ip-address/hostname

连接之后可以使用 logoutexit 关闭连接 SSH。

以下给出 Windows 终端连接 Ubuntu 样例, > 之后是在 Windows 下执行的命令。

> ping 192.168.64.128
正在 Ping 192.168.64.128 具有 32 字节的数据:
来自 192.168.64.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.64.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.64.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.64.128 的回复: 字节=32 时间<1ms TTL=64
192.168.64.128 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失)
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms
> ssh lzy@192.168.64.128
The authenticity of host '192.168.64.128 (192.168.64.128)' can't be established.
ED25519 key fingerprint is SHA256:kl7UUDIpwGFUkeYjH0XOFPZfrYQmG8uBNlOZWdJNcHY.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.64.128' (ED25519) to the list of known hosts.
lzy@192.168.64.128's password:
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 6.2.0-26-generic x86_64)
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
Expanded Security Maintenance for Applications is not enabled.
0 updates can be applied immediately.
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
*** System restart required ***
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
lzy@Ubuntu:~$ uname -a
Linux Ubuntu 6.2.0-26-generic #26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jul 13 16:27:29 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
lzy@Ubuntu:~$ logout
Connection to 192.168.64.128 closed.

# 关闭 SSH

使用 systemctl 关闭 SSH 服务

sudo systemctl disable ssh --now

再次开启 SSH 服务

sudo systemctl enable ssh --now

彻底卸载 OpenSSH

sudo apt autoremove openssh-server -y
更新于