電腦通過SSH連接Termux
本文轉載自 https://glow.li/technology/2015/11/06/run-an-ssh-server-on-your-android-with-termux/
轉載純粹為了備份。
With the brilliant Termux terminal emulator app you can run an SSH server on your Android.
Perviously I used SSHDroid to achieve this, but with Termux is much nicer because you have access to a working package manager.
Run the service
You neet to install the OpenSSH package
apt install openssh
and use following command to start the ssh server.
sshd
And there you go. Your ssh service is now running on port 8022.
ssh localhost -p 8022
Adding your Public key
You cant do password authentication in Termux, therefore you need to put your OpenSSH public key into the ~/.ssh/authorized_keys file.
This file will need to be created and permissions set to 600.
touch ~/.ssh/authorized_keys # Set Permissions to the file chmod 600 ~/.ssh/authorized_keys # Make sure the folder .ssh folder has the correct permissions chmod 700 ~/.ssh
If you do not have a OpenSSH key pair yet, you can generate one with the following command:
ssh-keygen
You may or may not enter a passphrase and if you dont specify otherwise, your key pair will have been saved under ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub. You can then add it to the ~/.ssh/authorized_keys with
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys
Then you can test it by connecting to your ssh service
# -i $PATH_TO_FILE/filename is only required if the id_rsa file is not ~/.ssh/id_rsa ssh localhost -p 8022 -i %PATH_TO_KEY-FILE%/%NAME_OF_KEY%
You can now use your private key (~/.ssh/id_rsa) to login to your Termux SSH Server. Simply copy it to your computer (by copying it to internal storage first [cp ~/.ssh/id_rsa /sdcard]) and use it in your ssh client.
OpenSSH
If youre using OpenSSH (on Linux or Cygwin) you can use it directly:
# -i $PATH_TO_FILE/filename is only required if the id_rsa file is not ~/.ssh/id_rsa ssh $IP -p 8022 -i %PATH_TO_KEY-FILE%/%NAME_OF_KEY%
PuTTY
If youre using PuTTY you will need to convert it to the PuTTY Private Key format first.
- Download and run PuTTYgen
- Load the private key (id_rsa)
- Save the private key as a *.ppk file.
- Download and run PuTTY
- Enter the IP address of your Android device and use port 8022
- Under Connection>SSH>Auth you can browse for the *.pkk file
- Click open
- You can leave "login as:" blank
You should now be connected to your Android device via SSH.
If it still doesnt work
killall sshd sshd -d
If it is still prompts you for a password you can enter sshds debug mode with the above command and see exactly why your key has been rejected. The reason usually are bad permission on either your home directory, your .ssh folder or your authorized_keys file.
The correct permissions are:
chmod 700 ~ chmod 700 ~/.ssh chmod 600 ~/.ssh/*
I hope in the future Termux will allow us to register sshd as a proper service which would automatically start on system boot. Right now I have the sshd command in my .bashrc file and I am using f="https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm">Tasker to launch Termux after boot. You can also use the Termux widget to quickly start sshd with a widget.
See also: Access the SSH server via USB instead of WiFi
推薦閱讀:
※控制與保護開關CPS安裝
※關鍵詞排名要注意哪些問題,墨子學院告訴你
※小米 2018 年上半年的表現如何?
※蘋果今年新機發布會時間預測
※創企深度剖析:健身O2O鼻祖Classpass是下一個獨角獸,還是科技泡沫?
TAG:SSHSecureShell | 計算機科學 | 科技 |