Setup public key ssh login and troubleshooting

Short note on how to setup ssh to login without a password

Generate and copy key

ssh-keygen -t rsa

Copy key

ssh username@remotehost mkdir -p .ssh
cat .ssh/ | ssh username@remotehost 'cat >> .ssh/authorized_keys'

Try logging in!

If that doesn’t work

Some host need proper permission and a second authorized_keys2

At the remote host

chmod 700 .ssh
cd .ssh
cp authorized_keys authorized_keys2
chmod 600 authorized_keys
chmod 600 authorized_keys2

SSH may settings may need to be modified

At the remote host

cd /etc/ssh
sudo vi sshd_config

Find the AuthorizedKeysFile line and uncomment it (or add it if it doesn’t exist)

AuthorizedKeysFile %h/.ssh/authorized_keys

Save file, restart sshd with

sudo service sshd restart

Further troubleshooting

Start a second instance of sshd on the remote machine, dump all output to console so you can diagnose

/usr/sbin/sshd -d -p 2222

On your machine, do

ssh -p 2222

Look for Authentication refused: in the logs, it should contains the reason your connection fails

Comparison between class and traits in Scala

Singleton Can create new instance Can have a constructor Can be inherited
Class No Yes Yes Yes
Abstract class No No Yes Yes
Trait No No No Yes
Object Yes No No No

Also a small trick: Since an object cannot be inherited, we need to create a trait (a trait make sure the object won’t have a constructor) with the common values and functions of the objects we wanted to create, then both object would inherit the trait, with one object expanding on the trait.

This construction can be applied to perform Enumeration inheritance in Scala (since Enums by convention are created as objects)

Rooting LG Kit Kat roms

I was pretty excited when LG releases their 4.4 ROM for my age-old phone. I even waited 4 months extra to update via their mobile support tool (because I’m rooted, so the only way to do an OTA update is a factory reset, the support tool allows you to keep your data intact). Anyway, this is a pretty big update, so it went on with a few hitch. First, the support tool halts in the middle when the phone was in download mode, so I panicked a little bit. But after reading around, I just press Retry on the support client (while the phone was still in download mode, and without even unplugging the USB), the second time the update went through.

But that’s not the last of my problem. As a power user, I also need root. The trusty root method of creating a “G_security” file in the root directory of the SD card that used to work for LG ROMs before 4.1 no longer works. The old root toolkits (mostly released in 2013) contained an old version of adb that will not detect the new Kit Kat ROM (it halts on calling adb wait-for-device), and even if you tried to type in commands manually (adb root), you get another error

adbd cannot run as root in production builds

I tried everything and there’s just no way to push the su and busybox binary to system, since the shell always run with uid = 2000, not uid = 0. All the root method mentioned on XDA Developers were released in 2013, and none worked with the new ROM.

After a lot of searching, I found a mention of towelroot in one thread. It’s a new root method, built upon a kernel exploit to root the then-new Galaxy S5. The developer doesn’t specifically state this root method is for the newer ROMs so it’s a bit hard to find. So I tried this and it work (albeit not really smooth). Here’s how

1. Go to towelroot homepage, click the lambda icon to download the apk

2. Use adb install tr.apk to install

3. On your phone, open towelroot and press “make it rain”

4. Reboot! Yes, towelroot said if everything is normal your phone will not reboot and you don’t need to reboot, but you need to reboot for the root to work. If you don’t reboot, superuser will try to update the su binary, and will fail!

5. After reboot, go to your SU app of choice (you may need to download and install one if you haven’t already) and update your su binary

This method works for an LG 4.4.2 ROM, and may be patched in the future, so this is for reference purposes only.