How to Fix Linux SSH: Permission denied (publickey).

I just got done setting up a user in my new developer environment on multiple boxes. I made sure to copy over the authorized_keys file exactly, including the correct 0600 permissions, but kept getting the "Permission denied (publickey)" error when trying to ssh into one box, even though all the others worked.

What finally solved it for me was to make sure the user's password is set:

# passwd <user>

If that doesn't work, make sure the user's .ssh directory is chmod 0700 and the user's authorized_keys file is chmod 0600.

[ad]

Android ANR keyDispatchingTimedOut

[ad]

I recently had some issues with my Mancala app where some users were experiencing frequent force closes and I could not figure out the reason for this behavior. Fortunately, with the help of Android's relatively new force close reporting features, I was able to get some insight into the issue. The big issue seemed to be an ANR keyDispatchingTimedOut error, which was something I had no idea about, and Google wasn't super helpful.

Here's an example of the "Dalvik threads" that were reported to me in the Android Developer Console. My understanding is that this is a list of threads and their stack traces at the time of the force close.

DALVIK THREADS:
"main" prio=5 tid=1 NATIVE
  | group="main" sCount=1 dsCount=0 s=N obj=0x4001d8c8 self=0xccc8
  | sysTid=9498 nice=0 sched=0/0 cgrp=default handle=-1345013672
  | schedstat=( 103942869 246185301 151 )
  at java.net.InetAddress.getaddrinfo(Native Method)
  at java.net.InetAddress.lookupHostByName(InetAddress.java:508)
  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:280)
  at java.net.InetAddress.getByName(InetAddress.java:310)
  at java.net.InetSocketAddress.(InetSocketAddress.java:110)
  at java.net.InetSocketAddress.(InetSocketAddress.java:89)
  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:62)
  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:88)
  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.java:927)
  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:909)
  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1152)
  at com.xoise.mancala.Mancala.checkUpdate(Mancala.java:203)
  at com.xoise.mancala.Mancala.onCreate(Mancala.java:45)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:4627)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:521)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  at dalvik.system.NativeStart.main(Native Method)

"SoundPoolThread" prio=5 tid=8 NATIVE
  | group="main" sCount=1 dsCount=0 s=N obj=0x43ee6dc8 self=0x22b020
  | sysTid=9506 nice=0 sched=0/0 cgrp=default handle=1204184
  | schedstat=( 854492 25299072 9 )
  at dalvik.system.NativeStart.run(Native Method)

"SoundPool" prio=5 tid=9 NATIVE
  | group="main" sCount=1 dsCount=0 s=N obj=0x43ee6e88 self=0x22b430
  | sysTid=9505 nice=0 sched=0/0 cgrp=default handle=1203920
  | schedstat=( 122071 25207520 2 )
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #2" prio=5 tid=7 NATIVE
  | group="main" sCount=1 dsCount=0 s=N obj=0x43ecfa48 self=0x13f1f8
  | sysTid=9504 nice=0 sched=0/0 cgrp=default handle=1189136
  | schedstat=( 3265379 22705078 15 )
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #1" prio=5 tid=6 NATIVE
  | group="main" sCount=1 dsCount=0 s=N obj=0x43ecf988 self=0x125a90
  | sysTid=9503 nice=0 sched=0/0 cgrp=default handle=1202768
  | schedstat=( 4425047 132843018 15 )
  at dalvik.system.NativeStart.run(Native Method)

"Compiler" daemon prio=5 tid=5 VMWAIT
  | group="system" sCount=1 dsCount=0 s=N obj=0x43ecd348 self=0x121228
  | sysTid=9502 nice=0 sched=0/0 cgrp=default handle=1184232
  | schedstat=( 1708986 15808104 6 )
  at dalvik.system.NativeStart.run(Native Method)

"JDWP" daemon prio=5 tid=4 VMWAIT
  | group="system" sCount=1 dsCount=0 s=N obj=0x43ecd2a0 self=0x120b08
  | sysTid=9501 nice=0 sched=0/0 cgrp=default handle=1184152
  | schedstat=( 2685545 5004884 22 )
  at dalvik.system.NativeStart.run(Native Method)

"Signal Catcher" daemon prio=5 tid=3 RUNNABLE
  | group="system" sCount=0 dsCount=0 s=N obj=0x43ecd1e8 self=0x120fa8
  | sysTid=9500 nice=0 sched=0/0 cgrp=default handle=1196024
  | schedstat=( 3875733 5920410 15 )
  at dalvik.system.NativeStart.run(Native Method)

"HeapWorker" daemon prio=5 tid=2 VMWAIT
  | group="system" sCount=1 dsCount=0 s=N obj=0x43111d58 self=0x129518
  | sysTid=9499 nice=0 sched=0/0 cgrp=default handle=1185056
  | schedstat=( 27954104 52368162 15 )
  at dalvik.system.NativeStart.run(Native Method)

This ANR, or Application Not Responding, error occurs when a process on the main thread takes too long (something like 5 seconds). Android kills that process and any related by design to spare the device's resources.

The solution is to run resource-expensive tasks on another thread, and then post, or update the main thread accordingly. A common use for this is network calls (and this was what my problem was). The following is an example of how to implement this logic, in my case to check if an update is needed:

private void checkUpdate() {
	SharedPreferences prefs = getPreferences(0);
	SharedPreferences.Editor editor = prefs.edit();
	
	long lastUpdateTime = prefs.getLong("lastUpdateTime", 0);
	long time = System.currentTimeMillis() / 1000;
	
	if (lastUpdateTime + 3600 * 24 < time) {
		checkNetworkUpdate();
		editor.putLong("lastUpdateTime", time);
		editor.commit();
	}
}

protected void checkNetworkUpdate() {
	Thread t = new Thread() {
		public void run() {
			try {
				URL updateURL = new URL("http://www.updateurl.com/");       
				URLConnection conn = updateURL.openConnection();
				conn.setConnectTimeout(3000);
				Scanner scanner = new Scanner(conn.getInputStream()); 
				scanner.useDelimiter("\\n");
				
				int curVersion = getPackageManager().getPackageInfo("your.package.name", 0).versionCode;
				int newVersion = 0;
				if (scanner.hasNext())
					newVersion = Integer.valueOf(scanner.next());
				
				final boolean displayUpdate = newVersion > curVersion;
				
				runOnUiThread(new Runnable() {
					public void run() {
						handleNetworkReply(displayUpdate);
					}
				});
			} catch (Exception e) {}
		}
	};
	t.start();
}

private void handleNetworkReply(boolean displayUpdate) {
	if (displayUpdate) {
		(new AlertDialog.Builder(this)).setMessage("An update is available!\n\nOpen Android Market to see the details?")
			.setTitle("Update Available")
			.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=your.package.name"));
					startActivity(intent);
				}
			})
			.setNegativeButton("No", null)
			.create()
			.show();
	}
}

Then just call checkUpdate() to perform the task. Note the major points of importance here being the Thread object with a run() method and the runOnUiThread() method of the Activity, which allows you to post data to the main UI thread.

View HTTP Response Headers

Just a quick note to share a site I found that comes in handy when needing to debug web troubles. You can use the site to handily view HTTP request and HTTP response headers to see exactly what's going on behind the scenes.

Web Sniffer

To be totally honest, I’ll probably end up creating my own site for this because I like to build things out for the fun of it.

[ad]

How to view where DNS has propagated all over the world

I just wanted to quickly share a nice tool that I use all of the time when transferring sites to different servers or just changing DNS entries. Sometimes it's hard to tell how long or if the DNS for your domain has updated in other regions in the world. In this case, I use WhatsMyDns.net. It's a neat tool that allows you to look up the current DNS listing for common entries (I really only ever need to use A or CNAME) in quite a few servers located around the world. Since DNS propagates differently by geographic region, this tool is a very good overview as to how users are accessing your site.

Also, if you're like me and constantly need to check your IP address and don't want to always search google for "whats is my ip", I'd recommend you bookmark whats my info, a simple, non-bloated site that gives you what just you're looking for.

[ad]