2. 安装与远程连接
2.1 虚拟机安装 Linux
对于初学者,最安全的学习方式是在虚拟机(Virtual Machine)中安装 Linux,不影响你现有的系统。
推荐工具:
- VirtualBox:免费开源,跨平台,适合入门
- VMware Workstation Player:个人免费,性能更好
- WSL2:Windows 子系统,适合轻量使用(Windows 10/11)
安装步骤概览(以 VirtualBox + Ubuntu 为例):
- 下载 VirtualBox:https://www.virtualbox.org/
- 下载 Ubuntu ISO 镜像:https://ubuntu.com/download/desktop
- VirtualBox 中新建虚拟机,分配至少 2GB 内存、20GB 磁盘
- 挂载 ISO 镜像,启动安装
- 按照向导设置用户名、密码、时区等
💡 提示: 💡 WSL2 用户快捷方式:在 PowerShell 中运行wsl --install -d Ubuntu即可一键安装。
2.2 SSH 远程连接
在实际工作中,Linux 服务器通常没有图形界面,你需要通过 SSH(Secure Shell)远程连接。
从 Windows 连接:
- Windows 10/11 自带 SSH 客户端,直接在 CMD/PowerShell 中使用
- 或者使用PuTTY、MobaXterm、Termius等工具
基本连接命令:
bash
# 基本 SSH 连接
ssh username@192.168.1.100
# 指定端口(默认 22)
ssh -p 2222 username@192.168.1.100
# 使用密钥登录(更安全)
ssh -i ~/.ssh/id_rsa username@192.168.1.100bash
The authenticity of host '192.168.1.100 (192.168.1.100)' can't be established.
ED25519 key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.1.100' (ED25519) to the list of known hosts.
username@192.168.1.100's password:
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-91-generic x86_64)
Last login: Sat Jun 20 10:30:45 2026 from 192.168.1.50
username@server:~$生成 SSH 密钥对:
bash
ssh-keygen -t ed25519 -C "your_email@example.com"bash
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_ed25519
Your public key has been saved in /home/user/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:AbCdEfGhIjKlMnOpQrStUvWxYz1234567890abcde your_email@example.com将公钥复制到服务器:
bash
ssh-copy-id username@192.168.1.1002.3 终端基础
终端(Terminal)是你与 Linux 对话的窗口。打开终端后,你会看到一个 提示符(Prompt):
bash
username@hostname:~$这个提示符包含以下信息:
- username:当前登录的用户名
- @hostname:主机名
- ~:当前所在目录(~ 表示家目录)
- $:普通用户提示符(#表示 root 用户)
⚠️ 注意: ⚠️ 重要:Linux 命令区分大小写!File和file是完全不同的东西。
获取帮助的五种方式:
bash
# 方式一:man 手册(最详细)
man ls
# 方式二:--help 参数(快速查看)
ls --help
# 方式三:info 文档(GNU 风格)
info ls
# 方式四:whatis 一句话简介
whatis ls
# 方式五:apropos 搜索相关命令
apropos "list directory"bash
$ whatis ls
ls (1) - list directory contents
$ apropos "list directory"
dir (1) - list directory contents
ls (1) - list directory contents
vdir (1) - list directory contents