Score:0

awk command not working for rbash user

in flag

I have created a rbash user(restricted user) vega and I have created softlinks for the following commands-: awk,ls,free,top etc. Am trying to run a script for resource utilization and some of the commands use awk.

If I run the below commands via admin am able to get the results:

admin@VD1-21-2-1:/home/vega$ free -m |grep Mem |awk '{print $3/$2 * 100.0}'
16.4827
admin@VD1-21-2-1:/home/vega$ top -b -n 1 -d1 |grep "Cpu(s)"| awk -F' ' '{print $2}'|awk -F' ' '{print $1}'
0.3

When I execute them via restricted user which I have created, I get below errors:

vega@VD1-21-2-1:~$ free -m |grep Mem |awk '{print $3/$2 * 100.0}'
-su: /usr/bin/awk: Permission denied

vega@VD1-21-2-1:~$ top -b -n 1 -d1 |grep "Cpu(s)"| awk -F' ' '{print $2}'|awk -F' ' '{print $1}'
-su: /usr/bin/awk: Permission denied
-su: /usr/bin/awk: Permission denied

I have used the following commands for soft link below:

sudo ln -s /bin/ls /home/vega/bin 
sudo ln -s /bin/top /home/vega/bin 
sudo ln -s /bin/free /home/vega/bin 
sudo ln -s /bin/awk /home/vega/bin 
sudo ln -s /bin/ssh /home/vega/bin

How to resolve this permission denied error and the command should give the correct output.

Replying to @terdon: Hi @terdon I tried your step and am getting as below:

vega@VD1-21-2-1:~$ echo $PATH /home/vega/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
without sudo it is not working: 

admin@VD1-21-2-1:/home/vega$ ln -s /bin/ls /home/vega/bin ln: failed to create symbolic link '/home/vega/bin/ls': Permission denied 

tried via root also:

root@VD1-21-2-1:~# ln -s /bin/ls /home/vega/bin ln: failed to create symbolic link '/home/vega/bin/ls': File exists 

Simple I want a restricted user to access all my commands without any issues?

hr flag
What softlinks did you create, exactly? Please [edit] your question with enough information for someone to reproduce the issue.
Praveen Kumar avatar
in flag
I have used the following commands for soft link below: sudo ln -s /bin/ls /home/vega/bin sudo ln -s /bin/top /home/vega/bin sudo ln -s /bin/free /home/vega/bin sudo ln -s /bin/awk /home/vega/bin sudo ln -s /bin/ssh /home/vega/bin
terdon avatar
cn flag
Please ***EDIT*** your question and include this information there. Comments are hard to read, easy to miss and can be deleted without warning. Next, please delete the links you created and then create new ones without using `sudo`. Also run `echo $PATH` as the vega user and confirm that `/home/vega/bin` is in the PATH variable. The error shows your user is trying to run the normal `/usr/bin/awk` command and not their own local `~/bin/awk`.
Praveen Kumar avatar
in flag
Hi @terdon I tried your step and am getting as below: vega@VD1-21-2-1:~$ echo $PATH /home/vega/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin without sudo it is not working: admin@VD1-21-2-1:/home/vega$ ln -s /bin/ls /home/vega/bin ln: failed to create symbolic link '/home/vega/bin/ls': Permission denied tried via root also: root@VD1-21-2-1:~# ln -s /bin/ls /home/vega/bin ln: failed to create symbolic link '/home/vega/bin/ls': File exists Simple I want a restricted user to access all my commands without any issues?
BeastOfCaerbannog avatar
ca flag
@PraveenKumar Again, as instructed before, please [edit] any additional info in your question and use code formatting as necessary! Your last comment is unreadable really and may drive users away from helping you!
Score:0
us flag

awk is not in /bin, it's in /usr/bin. So the command you need is

sudo ln -fs /usr/bin/awk /home/vega/bin

The -f flag will force the link to be replaced, you may need that given that you already have an invalid soft link.

You can check the location of any executable using which i.e.

which awk

and that will tell you where it's located.

Note that ssh is also in /usr/bin

Praveen Kumar avatar
in flag
above step done, still getting permission failed error: admin@VD1-21-2-1:~/rusers$ ls -larth total 8.0K lrwxrwxrwx 1 root root 8 Oct 11 13:07 ssh -> /bin/ssh lrwxrwxrwx 1 root root 12 Nov 3 16:03 awk -> /usr/bin/awk lrwxrwxrwx 1 root root 13 Nov 3 16:03 gawk -> /usr/bin/gawk lrwxrwxrwx 1 root root 14 Nov 3 16:03 igawk -> /usr/bin/igawk drwxr-x--- 2 admin versa 4.0K Nov 3 16:03 . drwxr-x--- 7 admin versa 4.0K Nov 8 10:38 .. admin@VD1-21-2-1:~/rusers$ pwd /home/admin/rusers
us flag
add -f to force the ln to overwrite the existing invalid link.
Praveen Kumar avatar
in flag
the force option also didnt help and still getting the permission denied error
us flag
You'll have to use rm to remove the links then
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.