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?