Welcome to the Linux Foundation Forum!
superuser
aznbun
Posts: 4
in Command Line
Hi, I am new.
I have a simple question.
On Ubuntu, I made a script:
#!/bin/bash
if [ "$(id -u)" = "0" ]; then
echo "superuser"
else
echo "no"
fi
if [ "$(id -u)" = "0" ]; then
echo "superuser"
else
echo "no"
fi
I called the file "boo".
When I run "boo" as a regular user it says "no". But when I sudo su it, it says "boo" is not a command. So, how do I make it output "superuser".
Hope this make sense.
0
Comments
-
After you run sudo su your system switches you to the root user and places you in the root home directory. Most likely you launched sudo su when in your chosen directory, but attempted to just call the script name while in the root home directory.0
-
So, how do I go back to my home directory.
On the command prompt is says I am at:
[email protected]:/home/bun/bin
When I "ls" in that directory I see all my files and also "boo".
But when I type "boo" in the command prompt I still get:
boo: command not found
I am stuck, think I am missing something very simple.0 -
If you want to stay in root, just type cd /home/<username>/
If you want to be as user, type exit <enter> first, then cd /home/<username>/0 -
It sounds like Ubuntu is placing the current directory ( $PWD) in the PATH thus you can call the program named "boo" that is in the current directory.
whenever you switch to root the PATH variable must be different.
Try with./boo
0 -
Thank you.
The "./boo" worked. But I thought "./" was implied.
I thought by default "./boo" = "boo".
Now, I can move on to the next section. Guess I will use "./" when I am a superuser mode.0 -
After you type sudo su, before you execute your script, type the path to your script.
Example, [email protected]:cd <path to your script> boo.0 -
aznbun wrote:Thank you.
The "./boo" worked. But I thought "./" was implied.
I thought by default "./boo" = "boo".
No. In fact, I find that to be a security flaw.0 -
or put the commands in a path defined in your path section , for regular files will be ok in /usr/local/bin , this will make the command launchable simply via "boo"0
-
Quick note:
The reason boo works for user X should be because of the fact that you have added /home/X/bin to the PATH (you can check the command out by writing echo $PATH in terminal). When switching to root the user no longer has any PATH entry to that particular folder thus writing boo checks folder /bin /sbin and such but cannot find the script. This is not true when using sudo since sudo is a nice way of doing su -c '/path/to/script/ sudo does the command as another user (namely root) and there the PATH is different
Hope that helped any other who wondered.
echo $PATH as user:
/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/XXX/bin
And sudo:
/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/XXX/bin
And as sudo su:
/sbin:/bin:/usr/sbin:/usr/bin
Note the difference. I'm using Centos so I'm not sure that sudo behaves in the same way on any other dist though.0
Categories
- 10.1K All Categories
- 35 LFX Mentorship
- 88 LFX Mentorship: Linux Kernel
- 504 Linux Foundation Boot Camps
- 279 Cloud Engineer Boot Camp
- 103 Advanced Cloud Engineer Boot Camp
- 48 DevOps Engineer Boot Camp
- 41 Cloud Native Developer Boot Camp
- 2 Express Training Courses
- 2 Express Courses - Discussion Forum
- 1.7K Training Courses
- 17 LFC110 Class Forum
- 5 LFC131 Class Forum
- 19 LFD102 Class Forum
- 148 LFD103 Class Forum
- 12 LFD121 Class Forum
- 61 LFD201 Class Forum
- LFD210 Class Forum
- 1 LFD213 Class Forum - Discontinued
- 128 LFD232 Class Forum
- 23 LFD254 Class Forum
- 569 LFD259 Class Forum
- 100 LFD272 Class Forum
- 1 LFD272-JP クラス フォーラム
- 1 LFS145 Class Forum
- 23 LFS200 Class Forum
- 739 LFS201 Class Forum
- 1 LFS201-JP クラス フォーラム
- 1 LFS203 Class Forum
- 45 LFS207 Class Forum
- 298 LFS211 Class Forum
- 53 LFS216 Class Forum
- 46 LFS241 Class Forum
- 41 LFS242 Class Forum
- 37 LFS243 Class Forum
- 10 LFS244 Class Forum
- 27 LFS250 Class Forum
- 1 LFS250-JP クラス フォーラム
- 131 LFS253 Class Forum
- 995 LFS258 Class Forum
- 10 LFS258-JP クラス フォーラム
- 87 LFS260 Class Forum
- 126 LFS261 Class Forum
- 31 LFS262 Class Forum
- 79 LFS263 Class Forum
- 15 LFS264 Class Forum
- 10 LFS266 Class Forum
- 17 LFS267 Class Forum
- 17 LFS268 Class Forum
- 21 LFS269 Class Forum
- 200 LFS272 Class Forum
- 1 LFS272-JP クラス フォーラム
- 212 LFW211 Class Forum
- 153 LFW212 Class Forum
- 899 Hardware
- 217 Drivers
- 74 I/O Devices
- 44 Monitors
- 115 Multimedia
- 208 Networking
- 101 Printers & Scanners
- 85 Storage
- 749 Linux Distributions
- 88 Debian
- 64 Fedora
- 14 Linux Mint
- 13 Mageia
- 24 openSUSE
- 133 Red Hat Enterprise
- 33 Slackware
- 13 SUSE Enterprise
- 355 Ubuntu
- 473 Linux System Administration
- 38 Cloud Computing
- 69 Command Line/Scripting
- Github systems admin projects
- 94 Linux Security
- 77 Network Management
- 108 System Management
- 49 Web Management
- 63 Mobile Computing
- 22 Android
- 27 Development
- 1.2K New to Linux
- 1.1K Getting Started with Linux
- 528 Off Topic
- 127 Introductions
- 213 Small Talk
- 20 Study Material
- 794 Programming and Development
- 262 Kernel Development
- 498 Software Development
- 923 Software
- 258 Applications
- 182 Command Line
- 2 Compiling/Installing
- 76 Games
- 316 Installation
- 53 All In Program
- 53 All In Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)