7

Well, this is not something that I want to do but I ask this question to know more about Shell configuration in Unix/Linux systems. So, the situation that I want an answer to is the following -:

As we have different shells made available to us by a Unix/Linux system is it possible for us to configure a different shell for every user authorized to access the system. So, let's say that Tom, Dick and Harry are 3 users authorized to use the system "Unix" and I want "Tom" to use the shell zsh , Dick to use tcsh and Harry to use the bash shell. How can I do this and is this even possible?

migrated from stackoverflow.com Jun 21 '14 at 23:27

This question came from our site for professional and enthusiast programmers.

  • Type man chsh and you should have your answer :) – IMSoP Jun 21 '14 at 23:09
8

First of all, valid shells are listed in /etc/shells. Any user can change their default shell by using chsh as long as it's in the /etc/shells file.

Second, if you want to add a shell to /etc/shells you can, if you remove an entry from there, especially /bin/sh you are probably going to screw up the system, because /bin/login will NOT normally launch off a shell that's not listed there.

More info is available in chsh(1), login.defs(5), and passwd(5) man pages.

This ability has been around for a long time (I believe BSD 4.x)

1

Yes, different users can have different shells setup. You can change them with, for example, the chsh command. To change the current user's shell to bash (assuming it's in /bin/bash):

chsh -s /bin/bash [username]

You can also modify your /etc/passwd file manually and change the part which specifies the shell for that user. For example:

root:*:0:0:System Administrator:/var/root:/bin/sh

The last part in each line of your /etc/passwd, which will look something like the line above, after the last :, specifies the shell for that user.

  • You really shouldn't modify /etc/passwd by hand though – taylorcressy Jun 21 '14 at 23:12
  • But lets say that I am a system administrator and I want to restrict the user to use a specific shell, can I do that and how? – AnkitSablok Jun 21 '14 at 23:13
  • Sure, if you don't know what you're doing! – Martin Dinov Jun 21 '14 at 23:13
  • can you like point me to an example or illustrate the example I took, how do I do that? – AnkitSablok Jun 21 '14 at 23:14
  • 2
    @AnkitSablok Your question doesn't mention restricting user's shells, only configuring them. Restricting a user from running a command (i.e. not letting them type bash at a tcsh prompt) is a very different question. – IMSoP Jun 21 '14 at 23:15
1

You can use chsh!

chsh -s /bin/sh user_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.