I am trying to understand how user permissions work in Linux. The kernel boots and starts
init as root, right? Init then runs startup scripts and runs
agetty), again as root. Agetty just reads user name and runs
login, still as root, I think. Nothing interesting yet. But what does login do? I wasn't able to find anything better than "it attempts to log in". Suppose login finds that password matches (and we trying to log in as usual user), how does it change user id? I thought that there should be system call for that but I wasn't able to find it (maybe I'm just blind?)
su has the 'setuid' bit set so when we run it, it always runs as root. But when we tell it to log in as usual user, it again needs to change user id. Do I understand correctly that the same "magic" happens in
login when they need to change user? If so, why have two different programs? Is there any additional sorts of serious business happening when running login?