-2

Default command is:

sudo apt-get update

I want to replace command (sudo) with the user name. For eg:

username apt-get update
karan
  • 1
  • 1
  • 2

1 Answers1

-5

Use alias username="sudo" from the terminal to change it temporarily.

For a permanent alteration, add the same text to ~/.bashrc. You can use:

vi ~/.bashrc

Or:

nano ~/.bashrc

to do this. If you try the vi route you will need to press i before entering the text, followed by the escape key, followed by :wq to save the file. If this doesn't work you probably need to update your version of vim, which you can do with this command:

sudo apt-get install vim

If, on the other hand you want to change sudo contextually, so you instead just type in the name of the currently logged in user, try creating a "usernames.sh" file with this command:

vi usernames.sh

Or:

sudo vi usernames.sh

Depending on where you are creating it. Then enter this text:

#!/bin/bash

shopt -s expand_aliases
alias $USER="sudo"

Make it executable using chmod +x usernames.sh then run this command:

./usernames.sh

To make it run every time you start the computer, type:

cp usernames.sh /etc/init.d

Followed by:

update-rc.d usernames.sh defaults

Again let me know if this works and if it's what you had in mind since, as I said, I do not have access to an Ubuntu terminal at the present time to test. If there are problems they can be fixed if I am made aware of them.

  • There's not reason to edit your bashrc with sudo, and nano vi makes no sense at all. – muru Oct 09 '17 at 06:34
  • That. And he probably means his actual username and if logged in with another that username. – Rinzwind Oct 09 '17 at 06:34
  • @Rinzwind what do you mean by "his actual username if logged in with another that username"? – Peter David Carter Oct 09 '17 at 06:41
  • He probably wants this codered apt-get update and when codegreen logs in codegreen apt-get update when codegreen has admin priviliges. – Rinzwind Oct 09 '17 at 06:43
  • Someone may wish to check to make sure the new solution works as I do not have access to an Ubuntu terminal at present – Peter David Carter Oct 09 '17 at 06:49
  • You probably mean alias $USER=sudo, but this won't work in the .bashrc (or rather .bash_aliases btw) if not added with the actual username. – dessert Oct 09 '17 at 06:52
  • 1
    The OP is not here but my guess is that other users might find out about sudo and try to execute it so that with this change, it would have a different name. Otherwise, it doesn't seem to make sense but perhaps the OP can enlighten us on his ultimate intentions. – jpezz Oct 10 '17 at 20:38