> 技术文档 > How to SSH into your Ubuntu machine from macOS as superuser

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:

sudo apt updatesudo apt install openssh-serversudo systemctl enable sshsudo systemctl start ssh

💻 Step 2: Find Ubuntu’s IP Address

On Ubuntu, run:

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:

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:

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:

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:

sudo systemctl start ssh

To enable it at boot:

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.