Ah, I finally found what was wrong.
After some investigation, it appeared that when I logged into the machine via ssh {username}@{host}
(via the libssh API), whoami
wouldn't reply username
, but, instead, replied root
(yes, root. 0:0, allmight, and everything. THE super-user).
I checked the /etc/passwd file, and, at my biggest surprise, username also had 0:0 userid.
root sources bash (whereas {username} would use rbash) in my environment. Hence the problem found above.
Now, why ssh switches to "name1" when "name1" and "name2" are aliases, and you run ssh name2@host
via libssh still remains obscure. But at least, I know why my connection above wouldn't work.