Simplest way to add multiple users in Cygwin

cygwin;

I've installed Cygwin but have trouble operating it conveniently. I'd like the ability to, for example, 'su peter' where peter has his own preference for home directory, and shell. I don't care about security. I do not need these "user accounts" to be visible to Windows' mechanisms.

I've been stymied in my efforts. I don't know how to set "no password required" in /etc/passwd. 'su' gives command not found.

(BTW, I did install Cygwin on a different machine several years ago with no problem. Am I fighting with recent "improvements"?)

Let me clarify my question. The facilities from /etc/passwd are: * assign a home directory. I want george and peter to have different directories. I do not care whether george and peter can modify each others files or not * I want george to be able to use a different shell from peter. I don't want goerge to need to type ** tcsh ** cd /home/george ** source .cshrc for every single shell that gets spawned. Is there an easy way to achieve this? Does the Windows facility even have the concept of preferred Cygwin shell?

Best Answer

I don't care about security.

I do not need these "user accounts" to be visible to Windows' mechanisms.

Every Cygwin user must have a corresponding Windows user.


How do I add a new user in Cygwin?

  1. Create a Windows User
  • Create the user in Windows (Start > Control Panel >Manage User Accounts > Add...)
  1. Create the corresponding Cygwin user
  • Run the following commands:

        mkpasswd -l > /etc/passwd
        mkgroup -l > /etc/group 
    
  • This will synchronise the Cygwin users and group with the Windows user account.

  • If you are in a Domain use -d instead of -l

  1. Set the users shell
  • Change the user's default shell as appropriate by modifying /etc/passwd (which is a plain text file

  • The format of the file is as follows:

         Username:Password:UID:GID:Info:Home:Shell
    
  1. Modify the user home directory permissions as appropriate for your needs

I don't know how to set "no password required"

If you really don't care about security and want no password use:

password -p username

From the passwd documentation:

Synopsis

passwd [OPTION] [USER]

Options

...

-p, --pwd-not-required no password required for USER.

Source passwd


Am I fighting with recent "improvements"?

From Cygwin version 1.7.34 onward /etc/passwd is no longer used by default to manage user accounts.

  • If /etc/passwd exists it will be used, but only to cater to existing installs and special situations.

  • If /etc/passwd doesn't exist you can still create it. See mkpasswd and mkgroup for more information.

Since version 1.7.34 Cygwin uses uses native Windows user management.

  • Active Directory if it is available,
  • SAM otherwise.

You should use the new mechanism to manage user accounts instead of /etc/passwd:

Starting with Cygwin 1.7.34, Cygwin uses an automatic, internal translation from Windows SID to POSIX UID/GID. This mechanism, which is the preferred method for the SID<=>UID/GID mapping, is described in detail in the Mapping Windows accounts to POSIX accounts.

Prior to Cygwin 1.7.34, the last part of the SID, the so called "Relative IDentifier" (RID), was by default used as UID and/or GID when you created the /etc/passwd and /etc/group files using the mkpasswd and mkgroup tools. These tools as well as reading accounts from /etc/passwd and /etc/group files is still present in recent versions of Cygwin, but you should switch to the aforementioned automatic translation, unless you have very specific needs. Again, see Mapping Windows accounts to POSIX accountsfor the details.

Source POSIX accounts, permission, and security:


su gives command not found.

Install sshd and use ssh username@localhost as a su replacement.

You can define a su alias to make this easier.

Why doesn't su work?

The su command has been in and out of Cygwin distributions, but it has not been ported to Cygwin and has never worked. It is currently installed as part of the sh-utils, but again, it does not work.

You should rather install sshd and use ssh username@localhost as a su replacement.

For some technical background into why su doesn't work, read About the 'su' command and related mail archive messages.

Source Why doesn't su work?

Related Question