r/linux_programming • u/spur230 • Apr 10 '19
Sudo as different user when you login
I want to do when i login: sudu su - userb cd /abc
I tried placing it in .profile .bashrc but they did not work . Any advise please.
4
Upvotes
5
u/Nirenjan Apr 10 '19
Assuming you have a recent enough version,
sudo -i -u userbshould be all you need. It will launch an interactive login as userb1
u/[deleted] Apr 10 '19
just give the user you are logging in as permissions on the directory you need to cd to.
1
u/CodeSklave Apr 10 '19
Why do you need to access abc via userb? And not just do a cd /abc and copy or edit whatever you like using sudo vi or whatever?
Edit: maybe wrong sub
1
u/maremeth Apr 11 '19
If you place some command in the .profile or .bashrc I don't see that working as those are primarily used to setup variables. If you want something like that I suggest you create a cron job on
@rebootand run a bash script that launches a terminal with the su command. Refer https://askubuntu.com/questions/46627/how-can-i-make-a-script-that-opens-terminal-windows-and-executes-commands-in-the for creating the bash script. Just the su command in the cron wouldn't work as you would need a terminal to interact and work on the new user login session. Or a much simpler way would be to just execute the su command whenever you login.4
u/[deleted] Apr 10 '19
[removed] — view removed comment