-1

This question is a bit specific and I want to do the equivalent of the following code:

 # these commands must be run as root
 root@server:$ useradd -m -s /bin/bash elspeth # add user named elspeth
 # -m creates a home folder, -s sets elspeth to use bash by default
 root@server:$ usermod -a -G sudo elspeth # add elspeth to the sudoers group
 root@server:$ passwd elspeth # set password for elspeth
 root@server:$ su - elspeth # switch-user to being elspeth!
 elspeth@server:$

 elspeth@server:$ sudo apt-get install nginx
 elspeth@server:$ sudo service nginx start

I click "Run as administrator" when opening the Command Prompt, which I assume is "running as root."

I did a little research and found commands like net user (username) (pwd) which I assume are Windows equivalents. Now first, the sudo group part I am confused. I enter:

net localgroup sudo (user) /add

but get a "The specified local group does not exist." Am I to just make a new "sudo" group?

There is also the part of the code setting a user to "use bash by default" of which I do not know/understand the Windows equivalent.

Lastly for the first chunk of code, there is a su command. Would runas be the equivalent? I read that you can switch users from the command prompt on Windows through runas but then I have to specify a program to run (would it be bash in this case?)

And from what I read on StackOverflow, runas is actually the Windows equivalent to Linux's sudo, which gets more confusing for me in the second chunk of code where we have to use sudo (and for what it's worth, sudo is an unrecognized command for me).

For reference and context, this is the book I am using and the exact excerpt dealing with this code: http://chimera.labs.oreilly.com/books/1234000000754/ch08.html#_user_accounts_ssh_and_privileges

Spag Guy
  • 565
  • 1
  • 5
  • 15
  • 1
    There is no particularly close Windows equivalent to most of what that code does. Why are you trying to follow instructions designed for Linux instead of using instructions designed for Windows? What do you actually want to achieve? (For example: in Windows there is nothing equivalent to the sudo group, no need to assign a particular shell to a user, *usually* no need for a sudo-like command, etc.) – Harry Johnston Apr 14 '15 at 05:39

1 Answers1

1

You can't just translate commands like that into Windows; Linux and Windows are completely different especially when it comes to user management.

sudo is just switch user do; it allows you to run a command as another user. In most cases, this is done to allow normal users to execute commands as root.

On Windows, this is "Run As Administrator"; or if you are already part of the Administrator's group - then you can skip this entirely.

The first line adds a user, assigns them a home directory and a shell.

In Windows, you simply add a user; as there really isn't a concept of "shell" in Windows - that is, all users by default use the Windows Desktop Environment - which is their "shell". A shell is just a program that accepts input for execution. Most texts will tell you that cmd.exe (or PowerShell) is the "shell", but this is not strictly true. These are just another interface to execute commands - the main "shell" is Windows itself.

Further, all users get a home directory by default (unless they are a system account).

For more on how to actually create the users and add them to groups, see PowerShell: Create Local User Account

Your last two lines are installing nginx; the closest thing for that command on Windows is chocolatey, but it needs to already be installed.

Otherwise, specifically for nginx you simply download the zip and run the command.

Community
  • 1
  • 1
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • This does help a lot, thanks. I just need some clarification. The book states "In these instructions, I’m assuming that you have a nonroot user account set up that has 'sudo' privileges" It later states you should deploy an app as a nonroot user (and this is what I'm doing -- deploying an app), so I'd like to follow the book's suggestion. So is the "sudo" equivalent then to simply "runas" the Administrator while logged in as some nonroot user? – Spag Guy Apr 14 '15 at 06:28
  • Yes, _but only on Linux_. Your non-root user should also be specifically granted access to execute commands using `sudo`. Generally, this is done by adding your non-root user to the `wheel` user group. – Burhan Khalid Apr 14 '15 at 06:37