Find the answer to your Linux question:
Results 1 to 7 of 7
how can i make an alias for a terminal command.... ? for example: when "/x" is typed, it will issue the "sw" command and type the root password...... if i ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Feb 2003
    Location
    Swansea (UK)
    Posts
    221

    Making Aliases for the terminal


    how can i make an alias for a terminal command.... ?

    for example:

    when "/x" is typed, it will issue the "sw" command and type the root password...... if i use this nobody will ever need to see my root password

  2. #2
    Linux Engineer
    Join Date
    Jan 2003
    Location
    Lebanon, pa
    Posts
    994
    To do something like that, I would use the expect scripting language to enter passwords for you. I don't think you will be able to do that with bash scripting. To create an alias you would type this
    Code:
    alias <command>="blah -l -a -b -whatever"
    I also suggest you look into using sudo. I rarely ever login with root since sudo can run commands as root and you can set it so you don't have to type in the root pw to use sudo.

  3. #3
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    It's absolutely not possible to script something like that. It would probably be dangerous to have that possibility, since it would probably have to be implemented using escape sequences. Think of the possibilities to execute commands as another logged in user with 'write', in that case. (In the Hurd, it would be possible to do it securely with a terminal translator, of course... I love the Hurd)

    Like genlee says, check out sudo instead.

  4. #4
    Linux Engineer
    Join Date
    Jan 2003
    Location
    Lebanon, pa
    Posts
    994
    Expect is designed for things like entering passwords or answering questions that the system asks. I have used except for entering my password for scripts that used scp or rsync. I personally would never leave a script on my box with my root password though, that is just askign for trouble if you allow others to have shells on your box.

  5. #5
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    It could be done with expect of course, but I can't say it's a smooth solution, though. (And leaving your root password in a file feels kind of stupid, too, of course...)
    In any case such as this, I'd much rather just make a suid bin that's just executable by me, which feels unnecessary when there already is sudo, though.

  6. #6
    Linux Newbie
    Join Date
    Feb 2003
    Location
    Swansea (UK)
    Posts
    221
    yeh i suppose, if you have a script like that then its basically saying to the hacker, "come and get me, my computer has easy access"

  7. #7
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Basically, yeah. If you're so worried of having to type your root password, maybe you should think of other means of authentication instead, such as smart card readers and stuff.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •