Simplest way to add multiple users in Cygwin?

3

2

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?

James Dow Allen

Posted 2016-02-16T10:56:14.907

Reputation: 39

Answer expanded to address your "clarification" – DavidPostill – 2016-02-16T12:41:03.723

Answers

5

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...)
  2. 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

  3. 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
      
  4. Modify the user home directory permissions as appropriate for you 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?

DavidPostill

Posted 2016-02-16T10:56:14.907

Reputation: 118 938

I'm happy to use /etc/passwd even if it is no longer the preferred way to go, if it can meet my objectives.

Please read my clarification above. – James Dow Allen – 2016-02-16T12:07:05.803

@JamesDowAllen Answer expanded to address your "clarification". – DavidPostill – 2016-02-16T12:39:17.670

I've followed the instructions. I've learned that the password field in /etc/passwd is stored plaintext -- that makes that part easy. :-)

BUT ssh peter@localhost gives me Internet connection refused (obviously I'm not intending to use internet) while ssh peter gives me "Could not resolve hostname".

login works better -- but still doesn't succeed: I get "no shell: /usr/bin/tcsh: no such file or directory" This despite that that file does exist; I've used it successfully; my desire for this alternate is convenience.

So ... thanks for the help! More help will be gratefully accepted. – James Dow Allen – 2016-02-16T17:32:02.163

@JamesDowAllen I don't know how to fix ssh (I don't use it). This link suggests that some tools (mintty) honour the passwd shell. It also gives you other ways to change the shell. Re: How does one change the default shell?. You might want to read the rest of that thread.

– DavidPostill – 2016-02-16T17:39:10.153

/usr/bin/tcsh in passwd should work. It works for me anyway (I just changed my passwd file. Ran another copy of Cygwin64 Terminal (aka mintty) and got tcsh – DavidPostill – 2016-02-16T17:45:36.843

What happens if you run tcsh in a bash shell? Does it work then? – DavidPostill – 2016-02-16T17:47:47.813

You could also try a reinstall of tcsh to see if that fixes things. Package is tcsh-6.19.00-2 – DavidPostill – 2016-02-16T17:54:19.717

When logged in to Windows 8 as 'admin' can start tcsh from bash and it works fine. Then, when I do 'startx' I need to type 'tcsh' followed by 'source .cshrc' in every window. I can't switch to 'peter' -- I see that it recognizes my password but complains about '/usr/bin/tcsh'.

If I login to Windows as 'peter' before starting cygwin, I get the right home directory but 'bash'. I also have the problem that peter's home directory is 755 and owned by admin. Normally I'd try to fix that with something like 'login admin' ; 'chown' but admin's password is '*' ... ... to be continued... – James Dow Allen – 2016-02-18T15:05:00.197

... So ... I guess next time as 'admin' I'll edit /etc/passwd again. Believe it or don't, once upon a time I was a fluent and competent Unix user. These days, Fedora's interface (and Cygwin) confound me. Is it just me? – James Dow Allen – 2016-02-18T15:07:34.953

How exactly are you "starting Cywin". 1/ Running "Cygwin 64 Terminal" 2/ cygwin.bat 3/ StartX? (1) should use the users login shell. (2) Explicitly uses bash (3) Seems to use bash (I'm not completely sure) – DavidPostill – 2016-02-18T15:18:43.350

I run fine on my Windows 7 laptop; it's a new computer I'm trying to set up (and to which I have limited access) that isn't working. Perhaps simplest will be to explain how I'm happen to be happily operating on the laptop and tell me what is the simplest way to do the same thing in the new environment.

I run 'cygwin.bat' and get a bash prompt. I then type 'su peter' and get a tcsh' prompt ... and it's tcsh all the way until I 'su' back. The default account and the peter account have the same userid and group id!! I have the two "accounts" for convenience, not security. ... to be continu – James Dow Allen – 2016-02-18T16:03:46.487

Perhaps the simplest way forward is for me to give 'peter' the same userid as Admin on the new computer, leaving only the strange /usr/bin/tcsh error to resolve. – James Dow Allen – 2016-02-18T16:07:33.460

As per my comment above cygwin.bat explicitly calls bash --login -i. Edit it and you will see. That's why you first get a bash prompt. – DavidPostill – 2016-02-18T16:13:27.837

Yes. I understand that. I thought my last two comments explain why that is irrelevant for my purpose. – James Dow Allen – 2016-02-18T17:22:07.007

@JamesDowAllen I've done what I can to help - I don't think there is anymore advice I can offer you :/ If this was helpful to you and answered your question, please don't forget to upvote/accept it. See accept an answer.

– DavidPostill – 2016-02-18T17:37:39.623

1Now that’s an impressively thorough answer. I find it hard to believe that it was neither accepted or upvoted (until now). – Anthony Geoghegan – 2016-09-01T13:16:38.470