How to Mirror Your Android Phone to Ubuntu

Do you know how to mirror an Android phone to a Linux system? This article will explain how to mirror an Android phone to the Ubuntu system using the Scrcpy software as an example.

1. Introduction to Scrcpy

First, let’s get to know Scrcpy.

Scrcpy is an open-source command-line tool designed for computer users to control their Android devices via Android ADB or USB data cable. It supports operations on Android devices through mouse and keyboard, and importantly, it does not require root access.

How to Mirror Your Android Phone to Ubuntu

2. Main Features of Scrcpy

  • Free and open-source
  • No root access required
  • Can run on Linux, Windows, and Mac systems
  • Clipboard sharing
  • Lightweight (native, displays only the device screen)
  • Performance (30~60fps)
  • Quality (resolution up to 1920×1080 or higher)
  • Low latency (35-70ms)
  • Fast startup (can start displaying within seconds)
  • Non-intrusive (does not require any program to be installed on the Android device)

3. Usage Requirements

  • The Android device system version needs to be Android 5.0 (API 21) or above.
  • Ensure that you have enabled ADB debugging on your device.
  • On some devices, you may also need to enable additional options to control with mouse and keyboard.

4. Installing Scrcpy on Ubuntu

Install through the default software repository with the following command:

sudo apt-get install scrcpy

Of course, you can also download the source code and compile it yourself, with the following commands:

# runtime dependencies
sudo apt install ffmpeg libsdl2-2.0-0 adb

# client build dependencies
sudo apt install gcc git pkg-config meson ninja-build \
                 libavcodec-dev libavformat-dev libavutil-dev \
                 libsdl2-dev

# server build dependencies
sudo apt install openjdk-8-jdk

5. Running Scrcpy on Ubuntu

Connect the computer and Android device via USB and execute:

scrcpy

Supports execution with command line parameters, view the parameter list:

scrcpy --help

6. Introduction to Scrcpy Features

1. Screen Settings

(1). Reduce Resolution

Sometimes, lowering the mirroring resolution of the device screen can effectively improve performance.

We can limit both the height and width to a certain size (e.g., 1024):

scrcpy --max-size 1024
scrcpy -m 1024  # short version

The shorter side will be scaled proportionally to maintain the display ratio of the device. Thus, a device with 1920×1080 resolution will display at 1024×576 resolution.

(2). Modify Bitrate

The default bitrate is 8Mbps. If you want to change the bitrate (for example, to 2Mbps):

scrcpy --bit-rate 2M
scrcpy -b 2M  # short version

(3). Limit Frame Rate

The frame rate can be limited with the following command:

scrcpy --max-fps 15

This feature is officially supported by Android only in Android 10 and later versions, but it may also be available in earlier versions.

(4). Crop Screen

The device screen can be mirrored after cropping to display part of the screen.

This feature can be used, for example, to only display one eye of the Oculus Go.

scrcpy --crop 1224:1440:0:0   # 1224x1440 at offset (0,0)

If –max-size is specified simultaneously, the resolution change will occur after cropping the screen.

(5). Lock Screen Orientation

scrcpy --lock-video-orientation 0   # natural orientation
scrcpy --lock-video-orientation 1   # rotate 90° counterclockwise
scrcpy --lock-video-orientation 2   # 180°
scrcpy --lock-video-orientation 3   # rotate 90° clockwise

This setting affects recording.

2. Screen Recording

You can record video while mirroring the screen:

scrcpy --record file.mp4
scrcpy -r file.mkv

Record without enabling screen mirroring:

scrcpy --no-display --record file.mp4
scrcpy -Nr file.mkv
# Press Ctrl+C to stop recording

In the display, “Skipped frames” will be recorded, although they are not displayed in real-time due to performance reasons. Each frame in the transmission has a timestamp, so packet delay variation does not affect the recorded file.

**3.**Connection Methods

(1). Wireless

Scrcpy uses ADB to connect to Android devices. Meanwhile, ADB can connect to Android devices via TCP/IP:

  • Connect your Android device and computer to the same Wi-Fi.
  • Get the IP address of the Android device (in Settings – About Phone – Status Information).
  • Enable the network ADB feature on the Android device: adb tcpip 5555.
  • Disconnect your device from the computer.
  • Connect to your device: adb connect DEVICE_IP:5555 (replace DEVICE_IP with the device’s IP).
  • Run scrcpy.

Lowering the bitrate and resolution may help with performance:

scrcpy --bit-rate 2M --max-size 800
scrcpy -b2M -m800  # short version

(2). Multiple Devices

If multiple devices are listed after executing adb devices, you must specify the device’s serial number:

scrcpy --serial 0123456789abcdef
scrcpy -s 0123456789abcdef  # short version

If the device is connected via TCP/IP to the computer:

scrcpy --serial 192.168.0.1:5555
scrcpy -s 192.168.0.1:5555  # short version

You can start multiple scrcpy instances simultaneously to display multiple devices’ screens.

(3). Automatically Start When Device Connects

You can use AutoAdb:

autoadb scrcpy -s '{}'

(4). SSH Connection

The local ADB can remotely connect to another ADB server (assuming both ADB versions are the same) to connect to the device remotely:

adb kill-server    # kill the local ADB server on port 5037
ssh -CN -L5037:localhost:5037 -R27183:localhost:27183 your_remote_computer
# Keep this window open

From another terminal:

scrcpy

To avoid starting remote port forwarding, you can force a forwarding connection (note the difference between -L and -R):

adb kill-server    # kill the local adb server on 5037
ssh -CN -L5037:localhost:5037 -L27183:localhost:27183 your_remote_computer
# Keep this window open

From another terminal:

scrcpy --force-adb-forward

Similar to wireless network connections, the following settings may help improve performance:

scrcpy -b2M -m800 --max-fps 15

4. Window Settings

(1). Title

The window title defaults to the device model. You can modify it with the following command:

scrcpy --window-title 'My device'

(2). Position and Size

You can specify the initial window position and size:

scrcpy --window-x 100 --window-y 100 --window-width 800 --window-height 600

(3). No Borders

Close the borders:

scrcpy --window-borderless

(4). Keep Window on Top

You can keep the window on top with the following command:

scrcpy --always-on-top

(5). Fullscreen

You can start scrcpy in fullscreen mode with the following command:

scrcpy --fullscreen
scrcpy -f  # short version

Fullscreen mode can be changed in real-time using MOD+f.

(6). Rotate

You can rotate the window with the following command:

scrcpy --rotation 1

Optional values are:

  • 0: No rotation
  • 1: Rotate 90° counterclockwise
  • 2: Rotate 180°
  • 3: Rotate 90° clockwise

Note that scrcpy controls three different orientations:

  • MOD+r requests the device to switch between portrait and landscape modes (if the foreground application does not support the requested orientation, it may reject the request).
  • –lock-video-orientation changes the orientation of the mirrored display (the device’s mirrored screen orientation to the computer). This affects recording.
  • –rotation (or MOD+← (left) and MOD+→ (right)) only rotates the window’s display. This only affects the display, not the recording.

5. Other Mirroring Settings

(1). Read-Only

Disable computer control over the device (such as keyboard input, mouse movement, and file transfer):

scrcpy --no-control
scrcpy -n

(2). Display Screen

If multiple displays are available, you can choose a specific display for mirroring:

scrcpy --display 1

You can find the display ID with the following command:

adb shell dumpsys display   # search for "mDisplayId=" in the output

The second display may only be controllable if the device runs Android 10 or above (it may display on the computer but cannot be operated through the computer).

(3). Keep Awake

Prevent the device from sleeping while connected:

scrcpy --stay-awake
scrcpy -w

After the program closes, the device settings will revert to normal.

(4). Turn Off Device Screen

When starting screen mirroring, you can turn off the device’s screen with the following command:

scrcpy --turn-screen-off
scrcpy -S

Or press MOD+o when needed.

To turn the screen back on, you need to press MOD+Shift+o.

On Android, the power button can always turn the screen on.

For convenience, if the event of pressing the power button is sent through scrcpy (by clicking the right mouse button or MOD+p), it will turn the screen off after a short delay.

The physical power button can still turn on the device’s screen.

This feature can also be used to prevent the device from sleeping:

scrcpy --turn-screen-off --stay-awake
scrcpy -Sw

(5). Render Expired Frames

To reduce latency, scrcpy by default renders the most recently decoded frame and skips any previous frames.

Force rendering of all frames (which may increase latency):

scrcpy --render-expired-frames

(6). Show Touches

Sometimes, you may need to show touch points during the demonstration (displayed on the device).

Android provides this feature in Developer Options.

Scrcpy provides an option to enable this feature upon startup and restore initial settings upon exit:

scrcpy --show-touches
scrcpy -t

Note that this feature can only display physical touches (touching the screen with your hand).

(7). Disable Screensaver

Scrcpy does not disable the screensaver by default.

To disable the screensaver:

scrcpy --disable-screensaver

6. Input Control

(1). Rotate Device Screen

Use MOD+r to switch between portrait and landscape modes.

Note that the switch will only occur if the foreground application supports the requested mode.

(2). Copy and Paste

Whenever the Android clipboard changes, it will be automatically synchronized to the computer’s clipboard.

All Ctrl shortcuts will be forwarded to the device. Among them:

  • Ctrl+c to copy
  • Ctrl+x to cut
  • Ctrl+v to paste (after the clipboard synchronization from computer to device is completed)

This generally operates as you expect.

However, the actual behavior depends on the foreground program on the device. For example, Termux sends SIGINT when Ctrl+c is pressed, while K-9 Mail creates a new email.

In this case, cut, copy, and paste (only available on Android >= 7):

  • MOD+c inject COPY (copy)
  • MOD+x inject CUT (cut)
  • MOD+v inject PASTE (paste) (after the clipboard synchronization from computer to device is completed)

Additionally, MOD+Shift+v can convert the content of the computer’s clipboard into a series of key events input to the device. This feature can be useful when the application does not accept paste (like Termux). Note that this feature may cause issues with non-ASCII encoded content.

Warning: Pasting content from the computer’s clipboard to the device (whether through Ctrl+v or MOD+v) requires the content to be saved to the device’s clipboard. Thus, any application can read it. You should avoid transferring sensitive content this way (such as passwords).

(3). Pinch to Zoom

Simulate “pinch to zoom”: Ctrl + hold and move the mouse.

More accurately, you need to hold Ctrl while pressing and moving the mouse. After releasing the left mouse button, any cursor operations will occur relative to the center of the screen.

Specifically, scrcpy uses a “virtual finger” to generate touch events at the opposite position relative to the center of the screen.

(4). Text Injection Preference

When typing, the system generates two types of events:

  • Key events, representing a key being pressed/released.
  • Text events, representing a text being input.

The program defaults to using key events to input letters. Only in this way can the keyboard function properly in games (especially the WASD keys).

However, this may also cause issues. If you encounter such problems, you can avoid it with the following operation:

scrcpy --prefer-text

(This may cause the keyboard to function improperly in games)

(5). Key Repeat

When you hold down a key, the program defaults to generating multiple key events. In some games, this may cause performance issues.

To avoid forwarding repeated key events:

scrcpy --no-key-repeat

7. File Transfer

(1). Install APK

If you want to install an APK, drag and drop the APK file (with a .apk extension) into the scrcpy window.

This operation will not show any changes on the screen but will output a log in the console.

(2). Push Files to Device

If you want to push files to the device’s /sdcard/, drag and drop the files (not APK files) into the scrcpy window.

This operation has no visible response and will only output logs in the console.

You can modify the target directory at startup:

scrcpy --push-target /sdcard/foo/bar/

(3). Hotkeys

In the following table, MOD is the modifier key for hotkeys. The default is (left) Alt or (left) Super.

You can use the –shortcut-mod suffix to modify it. Optional keys include lctrl, rctrl, lalt, ralt, lsuper, and rsuper. For example:

# Use the right Ctrl key
scrcpy --shortcut-mod=rctrl

# Use the left Ctrl, Alt, or Super key
scrcpy --shortcut-mod=lctrl+lalt,lsuper

Generally, Super refers to Windows or Cmd.

How to Mirror Your Android Phone to Ubuntu
  1. Double-click the black border to close the black border
  2. Clicking the right mouse button will light up the screen when it is off; otherwise, it will act as pressing the back button.
  3. Requires Android version Android >= 7.

All Ctrl + key hotkeys are forwarded to the device for processing, so they will be responded to by the current application.

(4). Custom Path

To use the ADB you want, you can set its path in the environment variable ADB:

ADB=/path/to/adb scrcpy

If you need to override the path of scrcpy-server, you can set it in SCRCPY_SERVER_PATH.

If there is any infringement, please contact us for deletion

Recommended Reading

Practical | A Wonderful File Upload Getshell
“Super Detailed | Share” A Step-by-Step Guide to Internal Network Penetration
Powerful Tool | Siusiu – Penetration Tool Management Suite
A Comprehensive XSS Scanner
Practical | A Bypass of Baota WAF Using Godzilla
BurpCrypto: Universal Website Password Cracking Test Tool
Quickly Filter Real IPs and Organize into C Segments — Lingyan
Automatic Port Detection and Cracking Tool T14M4T
Penetration Tool | Stateless Subdomain Cracking Tool (1 second scans 1.6 million subdomains)
For more exciting content, please followOrange Cat Learning Security:
Persistently learn and share daily; if you find the article helpful, please give a “Read Again” at the bottom

Leave a Comment

×