LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-10-2019, 01:30 PM   #1
spur230
LQ Newbie
 
Registered: Sep 2014
Posts: 4

Rep: Reputation: Disabled
sudo to userb when i log in as usera


At my work, i am only sudo to userb. As I had to do it multiple times in a day , I wanted to automatically sudu to userb by placing in my .profile

sudo su - userb ; cd ~/somedirectory


However, this is not working. I tried placing sudo to .bashrc but that did not work either.

could someone please point out what am i doing wrong?

Thanks
 
Old 04-10-2019, 01:32 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,327
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
It would be this:

Code:
sudo -u userb -i
See "man sudo"
 
1 members found this post helpful.
Old 04-10-2019, 01:35 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Perhaps try an alias in your profile?
Code:
alias ub=`sudo -u userb; cd ~/somedirectory`
 
1 members found this post helpful.
Old 04-10-2019, 02:03 PM   #4
spur230
LQ Newbie
 
Registered: Sep 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
sudo to different user worked. (sudo -u userb -i) but cd ~/somedir did not work.

It looks like change directory is happening for usera not the userb that i am sudoing to .
 
  


Reply

Tags
profile, sudo script



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch Log File Count number of "unknown userâ?ť algorithm soph75 Linux - Newbie 2 10-14-2014 04:50 AM
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
Unable to redirect all sudo messages to /var/log/sudo driftwood Linux - Server 2 10-18-2012 04:34 AM
SUDO - allow user joe to SU to usera sajjad02 Linux - Newbie 1 03-10-2005 01:25 PM
How to allow userA to su another user satimis Red Hat 3 07-05-2004 09:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration