You can't use yum
command with regular user like TOM
, Yum command just can be used by root power and if you have install a package with yum, every user can use it. But if you have tar
package you can change installation directory like following: ( If that package generated with GNU auto tools)
./configure --prefix=/home/myusername/bin
make; make install
and put /home/myusername/bin in your PATH
variable. With this solution that package just run with myusername username!
But if your file is a binary or txt file you just can set proper permission and if we look more precise and you want to write a program which works just with specific UID
and USERNAME
you can simply check UID variable because it's readonly and you can trust it. see below script and put it in a check.sh file: ( I wrote SHELLSCRIPT because here is Unix & Linux forum )
#!/bin/bash
COUNTER=0
FLAG=0
declare -r MYUID=500
declare -r USNAME=Sepahrad
for i in `cut -d: -f3 /etc/passwd`
do
COUNTER=$(( COUNTER + 1 ))
[ $i -eq $MYUID ] && TMP=$(head -n`echo $COUNTER` /etc/passwd | tail -n1 | cut -d: -f1) && [ "$TMP" == "$USER" ] && [ $MYUID -eq $UID ] && FLAG=1
done
if [ $FLAG -eq 1 ]
then
echo "Hello $USNAME ($UID)"
elif [ $FLAG -eq 0 ]
then
echo "You don't have permission to see thi file $USER ($UID)"; exit 1
fi
This script just runs for the user which has UID=500 and Sepahrad username. (You can change it by an editor) but if you don't want any user see your source even root you can compile it with shc
command like: shc -v -r -T check.sh