树莓派4B安装ubuntu20LTS后手动安装ssh-server

主要是让kimi查阅的现有资料,然后实践的,目前成功。
主要是用chroot这种方式安装。


树莓派 SD 卡离线安装 openssh-server 快速笔记
(电脑 x86_64 → ARM 树莓派,无需显示器)

  1. 插卡 → 确认设备

    lsblk -fp          # 记住 ext4 分区,如 /dev/sdc2
    
  2. 挂载 + bind(主机执行)

    sudo mkdir -p /mnt/{root,boot}
    sudo mount /dev/sdc2 /mnt/root
    sudo mount /dev/sdc1 /mnt/root/boot
    sudo mount --bind /dev  /mnt/root/dev
    sudo mount --bind /proc /mnt/root/proc
    sudo mount --bind /sys  /mnt/root/sys
    sudo mount --bind /run  /mnt/root/run
    
  3. 装 qemu-user-static 并拷模拟器

    sudo apt install -y qemu-user-static
    
    # ARM64 镜像
    sudo cp /usr/bin/qemu-aarch64-static /mnt/root/usr/bin/
    
  4. 进入 chroot

    sudo chroot /mnt/root /usr/bin/qemu-aarch64-static /bin/bash
    
  5. 装包 & 自启

    apt update
    apt install -y openssh-server
    systemctl enable ssh        # 仅生成链接,不会真正启动
    
  6. 改配置(chroot 内,我没有执行)

    sed -i 's/^#Port 22/Port 22/' /etc/ssh/sshd_config
    sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
    
  7. 退出并卸载

    exit
    sudo umount /mnt/root/{dev,proc,sys,run,boot,}
    
  8. 插卡回树莓派,通电 30 秒后验证

    nmap -p 22 192.168.0.191   # 应显示 22/tcp open ssh
    
  9. 若仍 closed,现场(或串口)执行

    sudo ufw disable
    sudo iptables -F
    

完成!

然后在我的主机上就可以扫描出来,并且可以连接了

$ nmap -p 22 192.168.0.191
Starting Nmap 7.80 ( https://nmap.org ) at 2026-01-18 20:57 CST
Nmap scan report for 192.168.0.191
Host is up (0.0015s latency).

PORT   STATE SERVICE
22/tcp open  ssh

Nmap done: 1 IP address (1 host up) scanned in 1.52 seconds

$ ssh pi@192.168.0.191
The authenticity of host '192.168.0.191 (192.168.0.191)' can't be established.
ED25519 key fingerprint is SHA256:L0sdrsaNtJvTSi+ytXC1eoKlk0kV/yJ5dB9RkADC3vM.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容