This guide explains how to set up and use ADB (Android Debug Bridge) shell and SSH to interact with your Android device.
Setting Up ADB
ADB allows you to issue basic Linux commands on your phone from your computer.
On Your Phone
- Enable Developer Options:
- Go to Settings > About phone.
- Tap on Build number seven times. You'll see a message confirming that Developer options have been enabled.
- Enable Android Debugging:
- Go back to the main Settings screen.
- You should now see Developer options under the "System" section (or directly in Settings, depending on your Android version).
- Tap on Developer options.
- Enable the "Android debugging" option (also known as "USB debugging").
- Tap OK on the verification prompt.
On Your PC
- Download Android SDK Platform-Tools:
- You can download the necessary ADB tools (Platform-Tools) from the official Android Developers website. Search for "Download SDK Platform-Tools."
- Estimated download time: 1-5 minutes, depending on your internet speed.
- Install the Tools:
- Unzip the downloaded
platform-tools
file to a convenient location on your PC, for example,C:\platform-tools
.
- Unzip the downloaded
- Install USB Drivers:
- Download and install the USB drivers specific to your phone's manufacturer (e.g., Samsung, Google, LG, etc.). These are crucial for your PC to recognize your phone.
- You can usually find these on your phone manufacturer's support website.
- Estimated download/installation time: 5-15 minutes, depending on the driver package.
- Connect Your Phone:
- Re-connect your phone to your PC using a USB cable.
- Verify ADB Connection:
- Open your Command Prompt (on Windows) or Terminal (on macOS/Linux).
- Navigate to the directory where you unzipped the
platform-tools
. For example, on Windows, typecd C:\platform-tools
and press Enter. - Type
adb devices
and press Enter. - On your phone, a prompt should appear asking you to "Allow USB debugging?" or "Allow connections from this computer?". Tap "Always allow from this computer" (recommended) and then "OK" or "Allow".
- If successful, your Command Prompt/Terminal should display your phone's ID (e.g.,
xxxxxxxx device
). If it shows "unauthorized" or nothing, it usually means the drivers aren't installed correctly or you haven't authorized the connection on your phone. - Troubleshooting: If the connection isn't established, try a different USB cable, a different USB port on your PC, or reinstalling the drivers.
- Access ADB Shell:
- Once your device is listed, type
adb shell
and press Enter. - You should now be connected to your phone's terminal, allowing you to run basic Linux commands.
- Once your device is listed, type
Using ADB Shell Commands
The adb shell
provides access to a command-line interface on your Android device. You can use many basic Linux commands like ls
(list files), cd
(change directory), cp
(copy files), mv
(move files), rm
(remove files), and more.
- Important Note: Many file and device management commands, especially those affecting system files or requiring elevated privileges, will require root access. Rooting your device is a separate and more complex process that can void your warranty and potentially brick your device if not done correctly. This guide does not cover rooting.
- For a comprehensive list of ADB commands, refer to Google's official Android Debug Bridge documentation.
Setting Up SSH Server on Your Phone
An SSH server app allows you to connect to your phone's shell remotely over a network, just like connecting to a Linux server. This is an alternative to ADB, especially useful for wireless access.
On Your Phone
- Install an SSH Server App:
- Go to the Google Play Store on your Android device.
- Search for "SSH Server" apps. Popular options include:
- SSH Server (by Ice Cold Apps)
- Servers Ultimate (can host various servers, including SSH)
- Termux (a powerful terminal emulator that can also run an SSH server)
- Install the app of your choice.
- Estimated installation time: 1-3 minutes.
- Configure the SSH Server App:
- Open the installed SSH server app.
- Follow the app's instructions to start the SSH server. You will typically need to:
- Set a username and password for SSH access.
- Note the port number (default is often 2222 or 8022, but can be configured).
- Ensure the server is running and active.
- Make sure your phone is connected to the same Wi-Fi network as your computer.
- Note your phone's IP address (usually displayed in the app or found in your phone's Wi-Fi settings).
On Your PC
- Connect via SSH Client:
- Linux/macOS: Open your Terminal. Use the
ssh
command: For example:Bashssh [username]@[phone_ip_address] -p [port_number]
ssh user@192.168.1.100 -p 2222
- Windows: Download and install an SSH client like PuTTY.
- Open PuTTY.
- In the "Host Name (or IP address)" field, enter your phone's IP address.
- In the "Port" field, enter the port number configured in your SSH server app (e.g., 2222).
- Select "SSH" as the connection type.
- Click "Open."
- When prompted, enter your username and password you set in the SSH server app.
- Estimated connection time: Less than a minute.
- Linux/macOS: Open your Terminal. Use the
Realistic Time and Cost Estimates
- Software Downloads (ADB Tools, USB Drivers, SSH App): Free. Download time 5-20 minutes total, depending on internet speed.
- Installation (ADB Tools, USB Drivers, SSH App): Free. Installation time 5-20 minutes total.
- Configuration (Developer Options, Android Debugging, SSH App Settings): Free. Configuration time 5-10 minutes.
- Hardware:
- Android Phone: Cost varies widely (from $100 to over $1000).
- USB Cable: Usually included with your phone; replacement cables cost $5-$20.
- Computer (PC/Mac/Linux): Required for ADB and SSH connections. Cost varies widely.
Total Estimated Setup Time:
- ADB Setup: 15-45 minutes (initial setup, excluding driver troubleshooting).
- SSH Setup: 10-25 minutes (after SSH app installation).
Total Estimated Cost: Primarily the cost of your existing phone and computer. All software tools mentioned are free.
http://android.stackexchange.com/questions/60906/terminal-on-real-android-device-from-pc
http://forum.xda-developers.com/nexus-4/help/guide-ultimate-nexus-4-root-guide-t2018179