Default command is:
sudo apt-get update
I want to replace command (sudo) with the user name. For eg:
username apt-get update
Default command is:
sudo apt-get update
I want to replace command (sudo) with the user name. For eg:
username apt-get update
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.
nano vi
makes no sense at all.
– muru
Oct 09 '17 at 06:34
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
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
alias username=sudo
– fkraiem Oct 09 '17 at 05:54sudo
isn't a user, it's a command... – Zanna Oct 09 '17 at 08:08alias
, as suggested by fkraiem – Zanna Oct 10 '17 at 20:13alias username='sudo '
(note the space at the end) to retain command completion forsudo
on its alias. – David Foerster Oct 10 '17 at 21:34