Re: 'alias' + sudo

2009-09-04 Thread Randy Belk
On Fri, Sep 4, 2009 at 10:50 AM, George Davidovich wrote:
> On Thu, Sep 03, 2009 at 08:10:36PM -0400, Jerry wrote:
>> On Fri, 4 Sep 2009 01:34:05 +0200 Mel Flynn wrote:
>>
>> > alias spico='/usr/local/bin/sudo pico -m' and be done with it.
>
> Instead of an extra alias, why not export $VISUAL or $EDITOR, and rely
> on sudoedit(8)?
>
>> That is what I am currently doing; however,there are other commands
>> that I want to use that are not available when used via sudo without
>> modifying the alias. I did not realize that sudo had such a
>> limitation.
>
> It's not a "limitation".  It's a feature.  ;-)  Re-read the sudo
> manpage.
>
> I'd be surprised if most of your aliases would ever require root
> privileges, and are anything but one-off shortcuts for your personal
> use.
>
> For those that do, I'd suggest replacing them with a function (or
> script) that tests for root privileges (using something like id(1)), and
> invokes sudo when appropriate.
>
> Otherwise, you may want to consider using 'su -m'.  That will your
> current environment unmodified and all your existing aliases will remain
> available for use.
>
> --
> George
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
>


There is a way for what you are wanting to do.
Make an alias for sudo that looks like this "sudo='sudo -E (Your default shell)"
Since I use zsh my alias looks like this sudo='sudo -E zsh'
It perserves all of your aliases, paths, and everything else

.

-- 
- Amiga, The Computer for the creative Mind!
- UNIX is basically a simple operating system, but you have to be a
genius to understand the simplicity.
- People who hate Microsoft Windows use Linux but people who love UNIX use BSD.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: 'alias' + sudo

2009-09-04 Thread George Davidovich
On Thu, Sep 03, 2009 at 08:10:36PM -0400, Jerry wrote:
> On Fri, 4 Sep 2009 01:34:05 +0200 Mel Flynn wrote:
> 
> > alias spico='/usr/local/bin/sudo pico -m' and be done with it.

Instead of an extra alias, why not export $VISUAL or $EDITOR, and rely
on sudoedit(8)?

> That is what I am currently doing; however,there are other commands
> that I want to use that are not available when used via sudo without
> modifying the alias. I did not realize that sudo had such a
> limitation.

It's not a "limitation".  It's a feature.  ;-)  Re-read the sudo
manpage.

I'd be surprised if most of your aliases would ever require root
privileges, and are anything but one-off shortcuts for your personal
use.

For those that do, I'd suggest replacing them with a function (or
script) that tests for root privileges (using something like id(1)), and
invokes sudo when appropriate.  

Otherwise, you may want to consider using 'su -m'.  That will your
current environment unmodified and all your existing aliases will remain
available for use.

-- 
George
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: 'alias' + sudo

2009-09-03 Thread Mel Flynn
On Friday 04 September 2009 02:10:36 Jerry wrote:
> On Fri, 4 Sep 2009 01:34:05 +0200
>
> Mel Flynn  wrote:
> > alias spico='/usr/local/bin/sudo pico -m' and be done with it.
>
> That is what I am currently doing; however,there are other commands
> that I want to use that are not available when used via sudo without
> modifying the alias. I did not realize that sudo had such a limitation.

It doesn't. alias has the limitation. As far as alias is concerned, a command 
is the first thing on the command line, and for good reason, as you don't want 
it to look further along the command line and attempt to expand everything.

So the shell only changes the command that is really run, when the first word 
matches an alias. Sudo or any app for that matter, never knew it was run 
through an alias.

However.reading through the bash manpage:
If the
   last character of the alias value is a blank,  then  the  next  command
   word following the alias is also checked for alias expansion.

So.:
$ alias sudo='/usr/local/bin/sudo '
$ alias pico='vim --version'
$ sudo pico
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jul 21 2009 13:22:46)
Included patches: 1-6, 8-35, 37-48, 50-70, 73, 75-87, 90-92, 94-100, 102-137, 
139-149, 151-171, 173-190, 192-193, 195-203, 206-209

Howeverbe aware of the consequences. If someone compromises your account, 
then setting:
alias ls='/tmp/mkroot'

and you running:
sudo ls

He just got root.
-- 
Mel
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: 'alias' + sudo

2009-09-03 Thread Jerry
On Fri, 4 Sep 2009 01:34:05 +0200
Mel Flynn  wrote:

> alias spico='/usr/local/bin/sudo pico -m' and be done with it.

That is what I am currently doing; however,there are other commands
that I want to use that are not available when used via sudo without
modifying the alias. I did not realize that sudo had such a limitation.

-- 
Jerry
ges...@yahoo.com

Recursion is the root of computation
since it trades description for time.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: 'alias' + sudo

2009-09-03 Thread Mel Flynn
On Wednesday 02 September 2009 13:26:59 Jerry wrote:
> I have set up several 'alias' definitions in my .bashrc file. They are
> honored when run as either a regular user or as root. However, when I
> prefix a command with 'sudo', the alias is no longer honored. In other
> words, the actual command is run;however, any flags that I was passing
> to it via 'alias' are lost. How can I circumvent this annoyance.
>
> Example, I often use 'pico' from within 'xterm'. I set up an alias that
> causes pico to use the mouse; i.e., pico -m which works fine as long as
> I do not prefix the command with 'sudo'

alias spico='/usr/local/bin/sudo pico -m' and be done with it.
-- 
Mel
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: 'alias' + sudo

2009-09-02 Thread Polytropon
On Wed, 2 Sep 2009 15:06:48 -0500, Dan Nelson  wrote:
> sudo does not run root's shell at all; it directly runs whatever is given it
> on the commandline.

Another idea would to be to call sudo with the desired shell as
argument (in order to inherit the aliases), followed by a command
as argument to the shell (in order to execute a particular command),
something like

% sudo bash -c "my_command_alias"

It may be possible that bash requires an additional argument to tell
it to read ~/.bashrc when invoked in a non-interactive manner.

Keep in mind that I haven't tried this solution because I don't
use bash on a regular basis.


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: 'alias' + sudo

2009-09-02 Thread Dan Nelson
In the last episode (Sep 02), Jerry said:
> On Wed, 2 Sep 2009 13:06:28 -0600
> Tim Judd  wrote:
> > Because sudo calls the binary, via SUID on sudo.  It doesn't pay
> > attention to user profiles or rc files (like .bashrc).
> > 
> > I don't use sudo, so I can't recommend past that.
> 
> In other words, sudo is not compatible with the bash 'alias' feature.  Is
> that correct?  I Googled and found several references to sudo and alias;
> however, no consensus on how to circumvent the problem.

sudo does not run root's shell at all; it directly runs whatever is given it
on the commandline.  Workarounds include creating an alias that includes
sudo in it (alias rootpicom='sudo pico -m'), or creating a shell script that
runs what your alias would have, so you can run "sudo picom":

/usr/local/bin/picom
  #! /bin/sh
  pico -m "$@"

-- 
Dan Nelson
dnel...@allantgroup.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: 'alias' + sudo

2009-09-02 Thread Jerry
On Wed, 2 Sep 2009 13:06:28 -0600
Tim Judd  wrote:

[snip]

> Because sudo calls the binary, via SUID on sudo.  It doesn't pay
> attention to user profiles or rc files (like .bashrc).
> 
> 
> I don't use sudo, so I can't recommend past that.

In other words, sudo is not compatible with the bash 'alias' feature.
Is that correct? I Googled and found several references to sudo and
alias; however, no consensus on how to circumvent the problem.


-- 
Jerry
ges...@yahoo.com

In response to President Obama's complaint that FOX News doesn't show
enough Black and Hispanic people on their network, FOX has announced
that they will now air "America's Most Wanted" TWICE a week.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: 'alias' + sudo

2009-09-02 Thread Tim Judd
On 9/2/09, Jerry  wrote:
> I have set up several 'alias' definitions in my .bashrc file. They are
> honored when run as either a regular user or as root. However, when I
> prefix a command with 'sudo', the alias is no longer honored. In other
> words, the actual command is run;however, any flags that I was passing
> to it via 'alias' are lost. How can I circumvent this annoyance.
>
> Example, I often use 'pico' from within 'xterm'. I set up an alias that
> causes pico to use the mouse; i.e., pico -m which works fine as long as
> I do not prefix the command with 'sudo'
>

Because sudo calls the binary, via SUID on sudo.  It doesn't pay
attention to user profiles or rc files (like .bashrc).


I don't use sudo, so I can't recommend past that.

--TJ
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


'alias' + sudo

2009-09-02 Thread Jerry
I have set up several 'alias' definitions in my .bashrc file. They are
honored when run as either a regular user or as root. However, when I
prefix a command with 'sudo', the alias is no longer honored. In other
words, the actual command is run;however, any flags that I was passing
to it via 'alias' are lost. How can I circumvent this annoyance.

Example, I often use 'pico' from within 'xterm'. I set up an alias that
causes pico to use the mouse; i.e., pico -m which works fine as long as
I do not prefix the command with 'sudo'

-- 
Jerry
ges...@yahoo.com

I just need enough to tide me over until I need more.

Bill Hoest
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"