![]() |
aliases for gainroot
I'm a linux n00b but i'm loving it. Today I discovered aliases and now I'm positively drunk with power. Only problem is that I find my aliases stop working as soon as I use sudo gainroot so that I can launch openvpn.
All I am trying to do is create an alias that will launch openvpn. Can't do this from the /home/user/.profile because openvpn needs root access. I have tried editing the /root/.profile and also the /etc/.profile but still no luck. Could anyone point me in the right direction for setting up aliases that will be available within the gainroot environment? clark |
Re: aliases for gainroot
Here's a suggestion:
Write a script to start OpenVPN with the config file you want, call it vpn, and place it in your path. Then, once you are root, you can simply type vpn to start up OpenVPN with your chosen config file. As far as I can tell the effect is exactly the same as having an alias called vpn which starts OpenVPN, which is what I think you are trying to acheive in a root environment. Anyway, if you want to try this and don't know how to then this entry in my blog has a script and all the info you need to set it up. Shouldn't take more than 3 or 4 minutes. Hope this helps - it works for me! |
Re: aliases for gainroot
Quote:
Code:
#!/bin/sh Append your code (i.e. vpn call) to the end. You can even create alias to this script i.e. put it to /home/user/bin call it vpn.sh and alias v=/home/user/bin/vpn.sh in your .profile and call it with 'v'. |
Re: aliases for gainroot
:D :D :D Well that just rocks. Thanks for the script header and tips on scripting a solution. I wrote a couple of scripts to shortcut a couple of tasks. One was launching openvpn and the other mounting a network share. I have to connect to several windows servers on a daily basis via rdc over vpn so I decided to get fancy and added commandline params to my scripts, then created an alias for each server that invokes the script and passes the relevant params for the particular server. Same thing for the network share mounting too.
I was wondering if it was possible to externalize the header to gain root access and then include it somehow, or better create a standalone script that establishes root access and exec that at the start of any script needing root acccess...but seeing as this gains root first, then relaunches itself....that may not be possible because of the recursive nature.? |
Re: aliases for gainroot
Quote:
Code:
#!/bin/sh Code:
#!/bin/sh Code:
#!/bin/sh Also please note that this is just a hack that (ab)uses gainroot script, correct way of calling something as root is to use sudo and add your scripts to /etc/sudoers (beware of messing up this file or change permissions, reboot loop needing reflash may be the result) |
Re: aliases for gainroot
Haha that's cool, thanks for explaining I think I can live with one line header :)
Seems like this sudoers file is a very fundamental part of linux and well worthy of some serious attention. From brief research I can see that there is a lot to learn about this, and it's very powerful given the correct understanding of syntax and logical structure. I am waiting for my MMC card to arrive so I can set up my device for booting from the memory and get easy backup/restore for the OS before I start experimenting with sudoers :) |
All times are GMT. The time now is 13:09. |
vBulletin® Version 3.8.8