Solved

how to fix alias command to user

Posted on 2011-02-14
10
771 Views
Last Modified: 2012-05-11
assume i made alias for the ls command
ls='ls -al' it works fine till i logg off
how i make it fix to the user ?
0
Comment
Question by:F_A_H_D
  • 5
  • 4
10 Comments
 
LVL 3

Author Comment

by:F_A_H_D
ID: 34886146
and there is any way to make the user permission to run one or two commands only ?
0
 
LVL 14

Expert Comment

by:sjm_ee
ID: 34886206
Put the alias in the file $HOME/.profile or, if the alias is specific to the shell that the user is running, put the alias in a startup script for that particular shell: $HOME/.kshrc for Korn shell. Remember that using .kshrc requires "ENV=~/.kshrc" or some such in "$HOME/.profile".
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34886207
Hi,

make the alias permanent by adding the alias command to the $HOME/.profile initialization file of the user.

As for the command restriction - that's not quite straightforward.

You will have to give the user a restricted shell in /etc/passwd, like /bin/rbash or /bin/rksh.
Next, you'll have to take away "user/group write" permission from the $HOME/.profile file of the user, change ownership to "root" so that it's only writeable by "root", set a PATH variable in this .profile to a directory where you must copy only the allowed binaries to, and finally make this PATH variable "readonly".

wmp

 
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 3

Author Comment

by:F_A_H_D
ID: 34886627
ok and for multi alias it should be like this
alias 506='piomisc_base get_job_status -P 'SHSPPI02''
alias 505='piomisc_base get_job_status -P 'SHSPPI01''
alias ls'ls -al'

?

and please can u make it more clear how to prevent the user to do any other thing .. except the alias commands
0
 
LVL 3

Author Comment

by:F_A_H_D
ID: 34886648
i noticed it doesnt take the second alias it give me error
$ 506
.status: (WARNING): 0781-102 Invalid printer name: SHSPPI02

but im sure the printer is there

and once i login it give error
.profile[10]: ^M:  not found.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 34886669
Seems that you edited the .profile under Windows and transferred it via FTP to Unix.
In this case take care to use "binary" transfer mode, else FTP will add a carriage return (^M) at the end of every line.

No need to have single quotes around the printer name.

alias 506='piomisc_base get_job_status -P SHSPPI02'
alias 505='piomisc_base get_job_status -P SHSPPI01'
alias ls='ls -al'

I'll come back to explain the command restriction!
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34886887
As I wrote, such a kind of restriction is a bit complicated.

Let's call your user myuser. Do the following as "root".

1)
usermod -s /bin/rksh myuser
-- I use rksh since I assume it's AIX, where ksh is the default shell!

2)
mkdir -p /usr/local/myuser/bin
-- The above directory name is just a suggestion. Use whatever directory location you like.

3)
ln -s /usr/sbin/piomisc_base /usr/local/myuser/bin
ln -s /usr/bin/ls /usr/local/myuser/bin

4)
chmod 755 ~myuser/.profile
chown root ~myuser/.profile

5) In ~myuser/.profile change/add:

-- remove a possibly present PATH definition
-- add:
PATH=/usr/local/myuser/bin
-- add:
readonly PATH
-- add your alias definitions. Attention: Each binary you use in such a definition must be linked to /usr/local/myuser/bin
alias 506='piomisc_base get_job_status -P SHSPPI02'
alias 505='piomisc_base get_job_status -P SHSPPI01'
alias ls='ls -al'

Save ~myuser/.profile , login as ~myuser and try it out.

wmp
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34886930
I just realized that for piomisc_base to work in a restricted shell you need to have three more binaries in the user's executables directory:

ln -s /usr/bin/tr /usr/local/myuser/bin
ln -s /usr/bin/awk /usr/local/myuser/bin
ln -s /usr/bin/dspmsg /usr/local/myuser/bin
0
 
LVL 3

Author Comment

by:F_A_H_D
ID: 34887135
Regarding the alias what u said is correct ... it works fine ater editing the file using vi

i will be back after trying the other proplem
0
 
LVL 3

Author Comment

by:F_A_H_D
ID: 34887153
thanks man
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
how to add IIS SMTP to handle application/Scanner relays into office 365.
This video discusses moving either the default database or any database to a new volume.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question