LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Cannot login with non-root username (https://www.linuxquestions.org/questions/linux-general-1/cannot-login-with-non-root-username-4175610333/)

wumy 07-21-2017 08:10 AM

Cannot login with non-root username
 
# uname -a
Linux iis-78-79-3f 3.14.26 #2 Wed Aug 24 13:52:28 CST 2016 armv7l GNU/Linux
fs: ramdisk + sysvinit + BusyBox(V1.26.2)
runlevel: 5

Description: After I created a non-root user with command "adduser", I tried to login with newly created username and failed. I failed both on console and with ssh. The command 'last' shows that the newly id has login successfully but logout immediately. I manually typed in 'login', and then feed with newly created username and passwd, and a string "Killed" prompted. When i modify the UID to 0 in /etc/password for the newly created username, then the login success, so the username and password are correct.
When i execute "strace su test", the last output is as following:
setgroups32(1, [1000]) = 0
setgid32(1000) = 0
setuid32(1000) = 0
execve("/bin/sh", ["sh"], 0xbe910dc0 /* 14 vars */) = ?
+++ killed by SIGKILL +++
Killed

I searched on web but no relevant page was found. It seems that only few people uses non-root user to login embedded system.
Is there something I missed?

MensaWater 07-21-2017 08:42 AM

Does /bin/sh exist? Is it a link to another shell (e.g. /bin/bash) and if so does that exist?

What /etc and user profiles exist appropriate to the shell you're actually calling? e.g. /etc/profile, /etc/bashrc, <userhome>/.profile, <userhome>/.bash_profile etc...

If you run "/bin/sh" from within a current shell does it work to open a subshell? (You can type exit to leave the subshell.).

Changing uid to 0 made the user the equivalent of root so it likely got the profiles for root rather than those for itself which may be why it worked.

wumy 07-22-2017 07:36 AM

Hi MensaWater,good day! thanks so much for your reply.
1. "/bin/sh" is a link of "/bin/busybox", and "/etc/profile" is exist.
2. Run "/bin/sh" on current shell can open a subshell successfully. I have written more than 10 scripts by using of "#!/bin/sh" which can be successfully run on the device.
3. I also did use another filesystem to replace my current filesystem, which can let the non-root user work normally. However, the result is the same as the previous.

So, is there any collision might be existed in my "linux kernel config" that result in such phenomena ?

scasey 07-22-2017 12:03 PM

Quote:

Originally Posted by wumy (Post 5738519)
3. I also did use another filesystem to replace my current filesystem, which can let the non-root user work normally. However, the result is the same as the previous.

I'm confused now. How is "the result the same as the previous" if it "let the non-root user work normally"

And what do you mean by "use another filesystem to replace my current filesystem"? That radical a change to what you're doing would completely muddy the waters.

Suggest you start over: Create a "normal" unprivileged user. Do not tweak the new user in any way, and see if it can do what you want.

Let us know what happens.

PS You missed answering an important question that MensaWater asked. To wit:
Quote:

What /etc and user profiles exist appropriate to the shell you're actually calling? e.g. /etc/profile, /etc/bashrc, <userhome>/.profile, <userhome>/.bash_profile etc...

wumy 07-23-2017 01:29 AM

Hi scasey, good weekend!
I'm sorry for the confused description. The so called "another filesystem" can work normally on a development board, not on my device.
The profile of "/bin/sh" is "/etc/profile", which existed in my filesystem already.

TheEzekielProject 07-23-2017 01:38 AM

After you ran
Code:

adduser username
did you
Code:

passwd username
? It sounds you created the user but never set a password

wumy 07-23-2017 07:47 PM

Hi TheEzekielProject, thanks for your reply.
In my device, adduser and passwd are both the link of /bin/BusyBox. When run adduser, the BusyBox will run passwd automatically.

# adduser hello
Changing password for hello
New password:
Bad password: too weak
Retype password:
passwd: password for hello changed by root
root@am335x-evm:~# busybox su hello
Killed

scasey 07-24-2017 02:48 PM

Quote:

Originally Posted by wumy (Post 5739097)
Hi TheEzekielProject, thanks for your reply.
In my device, adduser and passwd are both the link of /bin/BusyBox. When run adduser, the BusyBox will run passwd automatically.

# adduser hello
Changing password for hello
New password:
Bad password: too weak
Retype password:
passwd: password for hello changed by root
root@am335x-evm:~# busybox su hello
Killed

Do you have busybox configured to support the su command?
What happens if you
Code:

# su hello
I guess I don't understand why you're preceding the su with "busybox" when you didn't do that with adduser.
Also, it appears that you're running as root, so you won't (shouldn't) be prompted for a password when su-ing to a non-privileged user.

wumy 07-24-2017 07:45 PM

Hi scasey, thanks for your reply.
"busybox" supports lots of applets, such as ls, cd, login, su, find, syslogd, tftp, and so on. All these applets are the link of /bin/busybox.
Before use these applets, we should create soft link, such as "ln -s /bin/busybox ls". Otherwise should preceding the applet with "busybox", that's the reason of "busybox su hello".

wumy 07-24-2017 10:46 PM

I use "login" applet from "util-linux v2.13" to replace BusyBox's "login" applet, and add two "printf" lines in main function.
When executed "execvp" line, the shell disconnected:
int main(...) {
...
childArgv[childArgc++] = NULL;

printf("11\n"); // printed
execvp(childArgv[0], childArgv + 1);
printf("22\n"); // not printed

errsv = errno;

if (!strcmp(childArgv[0], "/bin/sh"))
fprintf(stderr, _("login: couldn't exec shell script: %s.\n"),
strerror(errsv));
else
fprintf(stderr, _("login: no shell: %s.\n"), strerror(errsv));

exit(0);
}

scasey 07-25-2017 02:20 AM

It looks like the user doesn't have a login shell defined, maybe. What does
Code:

grep hello /etc/passwd
show? [where "hello" is the newly created userid)

wumy 07-25-2017 02:45 AM

Hi scasey, thanks for your reply.
# grep "hello" /etc/passwd
hello:x:1000:1000:Linux User,,,:/home/hello:/bin/sh
# ls -l /bin/sh
lrwxrwxrwx 1 iis root 7 Jul 24 11:15 /bin/sh -> busybox
# ls -l /home/
total 9
drwxr-sr-x 2 hello hello 1024 Jul 25 15:43 hello
...

wumy 07-26-2017 03:09 AM

I added some "printk" in "fs/binfmt_elf.c" of kernel, and found the source of KILL signal:

static int load_elf_binary(struct linux_binprm *bprm)
{
...
error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
elf_prot, elf_flags, 0);
if (BAD_ADDR(error)) {
printk("kill3\n"); // printed
send_sig(SIGKILL, current, 0);
retval = IS_ERR((void *)error) ?
PTR_ERR((void*)error) : -EINVAL;
goto out_free_dentry;
}
...
}
Does anybody know the reason?

wumy 08-01-2017 10:03 PM

Hi all:
I solved this problem by modify the kernel config parameter CONFIG_DEFAULT_MMAP_MIN_ADDR from 65536 to default val 4096, which is a bug of kernel before v3.19.

see:https://bugs.launchpad.net/ubuntu/+s...x/+bug/1418140


All times are GMT -5. The time now is 11:29 PM.