Ask a Question related to Linux / Unix Administration, Design and Development.
-
Bing Du #1
how to become root in vi?
Greetings,
I was creating a file in a system privileged directory as me. When I
tried to save the file, of course, I got 'Can't open file for writing'.
How can I become root in vi (I can sudo to root) and then save the
file (very long) all done without leaving vi? I don't want to lose
anything I've just typed.
Thanks for any ideas,
Bing
Bing Du Guest
-
ExpandPath evaluates to ColdFusion root instead ofvirtual web server root
Hi, I am running ColdFusion MX7 on a Windows 2000 Server with IIS 5. The server is running multiple web sites using virtual hosting (host... -
Web content root ?= CF application root?
Are there any benefits to using a web content root that differs from the CF application root of (on Windows)... -
su from root
I have encountered an unusual issue where the behavior is different between FreeBSD 4.6 and 5.3. If I login and then su to root successfully,... -
Document root not website root
Could someone please help me with this. I want to use PHP in my website; but run into a snag, the recommended method of calling an include is:... -
ftp root
Hi all, How can I set the ftp root of user? By default, the ftp root of user abc is /home/abc. I want to set it as /home/aaa/folder. Is it... -
Dave Hinz #2
Re: how to become root in vi?
On Fri, 07 May 2004 16:07:11 -0500, Bing Du <bdu@iastate.edu> wrote:
Have you tried:> Greetings,
>
> I was creating a file in a system privileged directory as me. When I
> tried to save the file, of course, I got 'Can't open file for writing'.
> How can I become root in vi (I can sudo to root) and then save the
> file (very long) all done without leaving vi? I don't want to lose
> anything I've just typed.
sudo vi filename
....which should execute "vi" as root, and give you the permissions
you need to write to filename?
Dave Hinz
Dave Hinz Guest
-
S. Anthony Sequeira #3
Re: how to become root in vi?
On Fri, 07 May 2004 16:07:11 -0500, Bing Du penned:
Save the file in another directory and then, as root, move it where you> Greetings,
>
> I was creating a file in a system privileged directory as me. When I
> tried to save the file, of course, I got 'Can't open file for writing'.
> How can I become root in vi (I can sudo to root) and then save the
> file (very long) all done without leaving vi? I don't want to lose
> anything I've just typed.
>
> Thanks for any ideas,
>
> Bing
want it.
:w /dir/filename
--
Tony
Experience is directly proportional to the cost of the equipment ruined.
S. Anthony Sequeira Guest
-
Bing Du #4
Re: how to become root in vi?
That's too late. When I realized I did not have enough permission to
save the file, I had already been in vi. Thanks for the response.
Bing
Dave Hinz wrote:
> On Fri, 07 May 2004 16:07:11 -0500, Bing Du <bdu@iastate.edu> wrote:
>>>>Greetings,
>>
>>I was creating a file in a system privileged directory as me. When I
>>tried to save the file, of course, I got 'Can't open file for writing'.
>> How can I become root in vi (I can sudo to root) and then save the
>>file (very long) all done without leaving vi? I don't want to lose
>>anything I've just typed.
>
> Have you tried:
> sudo vi filename
> ...which should execute "vi" as root, and give you the permissions
> you need to write to filename?
>
> Dave HinzBing Du Guest
-
Bing Du #5
Re: how to become root in vi?
Ah, I kinda like this workaround. But still curious to know if there
would be a way that could save the file directly in the directory I
wanted. Thanks for the heads-up.
Bing
S. Anthony Sequeira wrote:
> On Fri, 07 May 2004 16:07:11 -0500, Bing Du penned:
>
>>>>Greetings,
>>
>>I was creating a file in a system privileged directory as me. When I
>>tried to save the file, of course, I got 'Can't open file for writing'.
>> How can I become root in vi (I can sudo to root) and then save the
>>file (very long) all done without leaving vi? I don't want to lose
>>anything I've just typed.
>>
>>Thanks for any ideas,
>>
>>Bing
>
> Save the file in another directory and then, as root, move it where you
> want it.
>
> :w /dir/filenameBing Du Guest
-
Dave Hinz #6
Re: how to become root in vi?
On Mon, 10 May 2004 08:06:41 -0500, Bing Du <bdu@iastate.edu> wrote:
Yes, then save it with a different filename, in a place where you have> That's too late. When I realized I did not have enough permission to
> save the file, I had already been in vi. Thanks for the response.
permission to write (/tmp at least, and/or your home account). Move it
using sudo to it's intended location. There isn't a way to become root
during a vi session that isn't more work than just saving it elsewhere
and moving it into the right place.
That having been said - how long do you go between saves? If you've made
so many changes that losing them would be painful, I would suggest that
you're not saving often enough.
Good luck,
Dave Hinz
Dave Hinz Guest
-
joe durusau #7
Re: how to become root in vi?
I wouldn't think that you could do that without doing something
that is inherently denagerous - like, maybe building a private copy of vi
that only you use and making it suid root. I certainly can't think
of any I would reccommend.
Speaking only for myself,
Joe Durusau
Bing Du wrote:
> Ah, I kinda like this workaround. But still curious to know if there
> would be a way that could save the file directly in the directory I
> wanted. Thanks for the heads-up.
>
> Bing
>
> S. Anthony Sequeira wrote:
>> > On Fri, 07 May 2004 16:07:11 -0500, Bing Du penned:
> >
> >> >> >>Greetings,
> >>
> >>I was creating a file in a system privileged directory as me. When I
> >>tried to save the file, of course, I got 'Can't open file for writing'.
> >> How can I become root in vi (I can sudo to root) and then save the
> >>file (very long) all done without leaving vi? I don't want to lose
> >>anything I've just typed.
> >>
> >>Thanks for any ideas,
> >>
> >>Bing
> >
> > Save the file in another directory and then, as root, move it where you
> > want it.
> >
> > :w /dir/filenamejoe durusau Guest
-
adam@cec.wustl.edu #8
Re: how to become root in vi
On Mon, 10 May 2004, Bing Du wrote:
Saving it then moving it is definitely your best and easiest way to go. You> Ah, I kinda like this workaround. But still curious to know if there
> would be a way that could save the file directly in the directory I
> wanted. Thanks for the heads-up.
might (MIGHT, I haven't and wouldn't test this, personally) be able to do
something funky like
:w !sudo cat > /filename/needing/root/privs
or something. I still wouldn't recommend it; anything you do as root opens you
up to potential problems, so it's best not to be too tricky.
adam@cec.wustl.edu Guest
-
Doug Freyburger #9
Re: how to become root in vi?
Bing Du wrote:
Use the "!" to get a subshell. Use sudo to get privileges. Use>
> I was creating a file in a system privileged directory as me. When I
> tried to save the file, of course, I got 'Can't open file for writing'.
> How can I become root in vi (I can sudo to root) and then save the
> file (very long) all done without leaving vi? I don't want to lose
> anything I've just typed.
"chown" or "chmod" on the directory in question so the regular user
your vi session is running as can write the file.
The cleaner apporach is to save it elsewhere and handle it outside
of vi.
Doug Freyburger Guest
-
Birger Blixt #10
Re: how to become root in vi?
On 2004-05-07 23:07, Bing Du wrote:
This is an ugly one :-)> Greetings,
>
> I was creating a file in a system privileged directory as me. When I
> tried to save the file, of course, I got 'Can't open file for writing'.
> How can I become root in vi (I can sudo to root) and then save the file
> (very long) all done without leaving vi? I don't want to lose anything
> I've just typed.
>
> Thanks for any ideas,
>
> Bing
>
:map W :!sudo chown $USER % ^M :w! ^M :!sudo chown root % ^M
where ^M is typed <ctrl>V<ctrl>M
Then save with W
If you are really brave, put it in .exrc
But seriously , save it in /tmp and copy the file as root later.
/bb
Birger Blixt Guest



Reply With Quote

