What's new

Ssh to router logging in as wrong user?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

William Higgs

New Around Here
Hello. I have a question regarding the firmware's capability that allows users to connect to their device via ssh. So, I have configured my router so that I can remotely connect to it via ssh using the router username and password, and I would expect, when logging into the router via ssh, I would login as the user account that I log into the router GUI as, but that is not what I am seeing. Instead, I appear to be logging in as the root account. I say "appear" because the starting directory that I am logging into is strange too. Normally, one would expect the user account's directory to be located in the /home folder, but the root user account that I am logging in as is located in the /tmp/home/root directory. Stranger still, in an attempt to have the router tell me where the home folder is located, I entered "echo ~/" into the console, and the router returned "/root". So we have three different folders that are potentially connected to the root account, which is the account that I automatically login is when I ssh to my router via "ssh username@ip" (username is NOT root). Is everything that I have described here by design? I just wanted to play around with the entware package manager, but the directory that the binary is located in is not in the PATH environment variable, so my thought was to modify the .bashrc file that autoruns when a user logs into the server to add the directory path to the PATH environment variable, but, as you can imagine, I am having trouble locating it. Even if there is another way to accomplish this, at this point, I just want to figure out what is going on with this router, as I get the impression that it is just as confused as I am.
 
Your post would be more readable if you broke it into paragraphs rather than presenting it as a wall of text.

What you are seeing is the consequence of running an embedded version of Linux that mostly resides in ROM and has almost no persistent storage.

The name of "root" account is whatever you call it when you setup the router, usually admin.

The root account's home directory is hard-coded to /root:
Code:
# grep admin /etc/passwd
admin:x:0:0:admin:/root:/bin/sh

As /root is in ROM there a symbolic link to another directory in RAM, /tmp/home/root.
Code:
# ls -al /root
lrwxrwxrwx    1 admin    root            13 Apr 26 20:27 /root -> tmp/home/root

The Entware directory is /opt. Again, because this is in ROM there is a symbolic link to whatever the path to your USB drive's directory is. /opt/bin and /opt/sbin are already in the default system PATH.
Code:
# ls -l /opt /tmp/opt
lrwxrwxrwx    1 admin    root             7 Apr 26 20:27 /opt -> tmp/opt
lrwxrwxrwx    1 admin    root            25 May  3 20:09 /tmp/opt -> /tmp/mnt/TOSHIBA1/entware
 
Last edited:
While the router is running Linux, it's a very custom and cut-down version. As for the "entware" directory you'll find it in tmp/mnt/yourUSBdevice
I'd probably also suggest using a tool such as Midnight Commander>
opkg install mc
will make exploring the file system so much easier!
 
The /etc/passwd file says the home dir is /root. /root is a link to /tmp/home/root.
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Staff online

Top