Joining a Linux Group Without Logging Out
Like most sites, I've had site traffic spikes on occasion. Sometimes it's for an article I wrote. Sometimes it's someone stealing my bandwidth, linking to pictures I host. I like to know what's going on, so I browse my server log files. Normally, I just remote in and fire up vi, but what if something goes wrong one day? Also, what if I want to filter the data without using the server's CPU time? I decided that I should back up my log files or a more regular basis.
I didn't want root on my PC to do anything it doesn't have to; I'd rather use a standard user. I'll just use my normal user account. I'll just modify my crontab and be done with it.
[~]$ crontab -e cannot chdir(/var/spool/cron), bailing out. /var/spool/cron: Permission denied [~]$
Even though cron is running, I never realized that I didn't add the group to my user account. I'll just add myself to the cron group to give myself permission.
[~]$ su -c "usermod -a -G cron $USER" Password: [~]$ crontab -e cannot chdir(/var/spool/cron), bailing out. /var/spool/cron: Permission denied [~]$
I forgot that my new group settings won't take effect until I log out and back in again. I have a few processes which have been running for a couple of days and still need more time before they are done. I don't want to log out.
There's a trick, though, because of the way permissions work. All new processes that I run are started as a subprocess to my current shell. I need to somehow re-log in without logging out. This will give me a completely new shell with a new set of permissions, giving me access to
/var/spool/cron . There's nothing that says that I can't use su to switch from myself to myself.
[~]$ su - $USER Password: [~]$ crontab -e crontab: installing new crontab [~]$ logout [~]$
It's as simple as that.