Termux install sshd(SSH)

SSH into Your Phone: A Detailed Guide for Accessing Termux from Your Computer


1. Install OpenSSH Upgrade your package on Termux with
pkg upgrade
then use the command
pkg install openssh
to install OpenSSH. 2. Set Passwords Use the 'passwd' command to set a password. 3. Find Username Run the
whoami
command on Termux, it will tell you your username. Save this value for later use, it may be in the form of 'u0_a254'. 4. Find Host Run
ipconfig
command on Termux, and there will be a form similar to 'inet addr:192.168.0.100' in the results, note down this value. 5. Start the SSH Server on Termux Start the server with the
sshd
command, and confirm whether the server is listening through the
logcat -s 'ssh:*'
command. If it successfully starts, you will see a message similar to "Server listening on port 8022". 6. SSH Remote Login from Your Computer On your computer, use the
ssh <username>@<host> -p8022
command, where username and host are what you got in the previous steps. Then enter the password you set on Termux, and there you go! You are now successfully accessing Termux on your phone from your computer. Please remember that the operation of ssh depends on your network settings. If you encounter problems in the ssh part, it may be because your phone is using cellular network instead of WiFi, you can try the
sshd -e -d -d -d
command.


Change SSH Port if Needed

  • To change the SSH port:

  • Log on to the server as an administrator.

  • Open the SSH configuration file sshd_config with the text editor vi:
    vi /etc/ssh/sshd_config

  • Search for the entry Port 22.

  • Replace port 22 with a port between 1024 and 65536


  • To establish an SSH connection after this change, enter the following command:
    ssh root@IP_address_of_the_server -p NewPort

      [REFERENCES]




#!/bin/bash # Upgrade Termux packages pkg upgrade -y # Install OpenSSH pkg install openssh -y # Install termux-api pkg install termux-api -y # Set password for SSH automatically echo -e "123456\n123456" | passwd # Retrieve and display the username USERNAME=$(whoami) echo "Your username is: $USERNAME" # Retrieve and display the IP address IPADDR=$(termux-wifi-connectioninfo | awk -F'"ip":' '{print $2}' | awk -F'"' '{print $2}' | tr -d '[:space:]') echo "Your IP address is: $IPADDR" # Start the SSH server sshd echo "OpenSSH has been installed and the server has been started." echo "You can connect using the following:" echo "Username: $USERNAME" echo "IP Address: $IPADDR" # Provide the SSH command for the user echo "To connect via SSH, use the following command:" echo "ssh $USERNAME@$IPADDR -p 8022"
#Delete Saved IP ssh-keygen -f "C:\Users\xxxREPLACE_USER_PROFILE_NAMExxx\.ssh\known_hosts" -R "[192.168.2.128]:8022" #Connect SSH IP ssh u0_a255@192.168.2.128 -p8022

Comments

Popular posts from this blog