Skip to content

Instantly share code, notes, and snippets.

@dmpatel151282
Last active November 23, 2023 02:07
Show Gist options
  • Save dmpatel151282/e606bae58c7b601e9d8d4aeed164f28d to your computer and use it in GitHub Desktop.
Save dmpatel151282/e606bae58c7b601e9d8d4aeed164f28d to your computer and use it in GitHub Desktop.
SSH server support in Android AOSP

SSH server support in AOSP Android

Download the OpenSSH source code and replace it with existing source code inside external folder.

Add below code in device make file (e.g. device.mk).

PRODUCT_PACKAGES +=
scp
sftp
ssh
sshd
sshd_config
ssh-keygen
start-ssh
passwd

Download ssh.rc file.

Add below lines in device make file to copy ssh.rc file from source folder to specified destination path.

PRODUCT_COPY_FILES += \
    <source_folder_path>/ssh.rc:$(TARGET_COPY_OUT_SYSTEM)/etc/init/ssh.rc \

Download start-ssh.te file and put at proper place in vendor sepolicy folder.

Add below lines inside file_context file in vendor sepolicy folder.

#ssh
/system/bin/start-ssh   u:object_r:start-ssh_exec:s0

There are two ways of authentications.

  • PubkeyAuthentication

  • PasswordAuthentication

PubkeyAuthentication

Follow the below steps.

  • Generate public private keys using PuttyGen and saved both keys.

  • Rename public key file to 'authorized_keys' and write line in device make file to copy file inside /system/etc/ssh folder at build time.

  • Uncomment below line in ssh.rc file at end of "on post-fs-data" section.

copy /system/etc/ssh/authorized_keys /data/ssh/authorized_keys

PasswordAuthentication

The code is already added in openssh source code.

To change password, open start-ssh file and change the passwords for root and shell users as per your requirements. Default password for root is SSH_ROOT@1234 and for shell is SSH_SHELL@1234. First entry is password and second entry is confirm password.

By default, ssh service will start after boot completed. If you would like to start service on property change then provision is provided in ssh.rc file. You just need to comment/uncomment lines in ssh.rc file.

It's time to build the code.

Contact me if you face any difficulty or would like to work with me.

https://prabhusystemtech.com/2021/11/10/ssh-server-support-in-aosp-android/

#AOSP-Android #PasswordAuthentication #PubkeyAuthentication #SSH Server #SSH Server Android #SSH Server Android Build #SSH Server in Android #SSH Server Support #OpenSSH #Android

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment