Connecting an Android Phone to a Linux PC to do important things ™

telephone

So randomly today I was tooling around and I thought “I want to connect my phone to my PC so I can do stuff on the PC remotely.”

First I set up an SSH connection, but later I managed to get a remote desktop login working. The remote desktop is not quite there yet, so Part 2 of this post series will deal with that once I think it’s working a bit better.

SSH connection: easiest way

So the first thing that’s super easy to do and super secure and works nicely is an SSH connection. It’s a command line interface though.

What you have to do, you have to enable SSH connections on your PC for a start. Here’s a link for how to do it on Manjaro, if you have another OS it’s easy enough to google how to do it.

One thing you’ll want to do if you’ve not set up SSH keys on your PC before is generate them now. ivermectin 12 mg tablet uses in marathi It’s as simple as:

ssh-keygen -t rsa

This command will generate a new ssh key pair and store it in two files in the ~/.ssh folder. The one called id_rsa contains your private key, the one called id_rsa.pub is the public one.

Setting up SSH on the phone side

I use an Android phone, so I needed an Android SSH client. After a bit of googling around and trying a few, I settled on ConnectBot, which is free, open source and free of ads.

Test connection

You’ll need to figure out the IP address of your server on your local network for this bit. In my case this is 192.168.1.35, it’s not static though. Anyway, you’re gonna connect to it using the format username@hostname:port – and supply a password when challenged. Just login using the user you usually login to the PC with. ivermectina 6mg para q es It should work.

Disable SSH login via passwords

The other thing you do want to do when you enable SSH is disable login via password. Especially if you’re gonna leave your SSH server running automatically every time you start up, you don’t wanna have your super insecure root user password guessed by some random chump passing by. To disable password access to your SSH server you gotta edit the file /etc/ssh/sshd_config and find the line that looks like this:

# PasswordAuthentication yes

That # is a comment out, so we’re gonna remove that, and we’re gonna say a big fat NO to password auth, thusly:

PasswordAuthentication no

So that’s done, but how the heck do we log in to the SSH server if we can’t use a password?

Generate an SSH key pair on the phone

ConnectBot lets you do this in the app. Once you’ve generated a key in the app you can copy the public key and register it on your PC (enter the command on the PC) thusly:

echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCpKyfMWaplgH9ToNJvq3UU/hjdFy6vED04BcpSCJ6FUC2p9A1T8v5UeoQ6P/Z5hbupu7vvJw6K5MYz6vk3+S/YHfrB4920mnWEaZNqJNDU919DDuaE6KIwN/l2PrPMp0tR9hibxjKGHhGlphJnQ+nqKW61tX06heABFY5a2ppDE99oaeh7ixkEs2y99IVdQ7/pUDAWXFM4WMv5ns+RYI1SvFAXbvxp3YDd/IDhSqVdVgchiMHiuAc4UV52+1rWbAxEyZl5XB5fDETEWdmyi2cr2cmIuVemJPz5JPD/cE3YK0i1puwZE/ftldNjxWJ81cungdtWR+MZ/Ha6GueSn+mv Dave key" >> ~/.ssh/authorized_keys

Obviously you’ll need to replace the key above, which is for my phone, with your own one that ConnectBot generated for you. I emailed the public key to myself from my phone to the PC – it’s public so there’s no security issue with doing so.

Now set your ConnectBot connection to connect using the key pair, and you can securely login to your PC from your phone without needing to enter a password.

Install a better keyboard

So now we’ve got Linux command line on the remote host, which is the PC, but it’s annoying ‘cos stupid Google keyboard on the phone wants to autocomplete stuff. Fortunately you can google Hacker’s keyboard and find a number of keyboards which are better suited to using for Linux commands. using ivermectin topically I found this one, which importantly lets me use a tab key which gives me tab completion without which I cannot live.

Finale

Once I established an SSH connection from my phone to the PC I spent some time cackling a bit, but then I realised that I didn’t really have anything that I wanted to do using the phone… I guess if I wanted to I could use the public IP of the PC to login from the other side of the world but due to Covid I guess at best I can run terminal commands from the bedroom or the bathroom. Anyway, it’s still fun.

About the Author

I’ve got some experience writing code. I run quite a lot. The last book I read was about Gavrilo Princip. There’s about to be a thunderstorm here. Here is Johannesburg, South Africa. There is another Johannesburg in the USA. I know how to make chocolate sauce.