How to SSH into your Ubuntu machine from macOS as superuser

To SSH into your Ubuntu machine from macOS as superuser, you'll first connect as a regular user, then elevate privileges once logged in.

Here's how to do it step by step:

🧭 Step 1: Enable SSH on Ubuntu

Make sure the SSH server is installed and running:

bash 复制代码
sudo apt update
sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh

💻 Step 2: Find Ubuntu's IP Address

On Ubuntu, run:

bash 复制代码
ip a

Look for your active network interface (e.g., wlp3s0 or enp0s25) and note the inet IP address (e.g., 192.168.2.7).

🛜 Step 3: SSH from macOS Terminal

On your Mac, open Terminal and run:

bash 复制代码
ssh username@192.168.2.7

Replace username with your Ubuntu account name and 192.168.2.7 with your actual IP.

🔐 Step 4: Elevate to Superuser

Once connected, run:

bash 复制代码
sudo -i

This gives you a root shell, assuming your user has sudo privileges.


🔍 To check if the SSH server is running on your Ubuntu system:

bash 复制代码
sudo systemctl status ssh
  • If it says Active: active (running), your SSH server is up and running.

  • If it says inactive or failed, it's either stopped or encountered an error.

To start it:

bash 复制代码
sudo systemctl start ssh

To enable it at boot:

bash 复制代码
sudo systemctl enable ssh

⚠️ Warning : Direct root login over SSH is risky. It's safer to log in as a regular user and use sudo.