Header Ads

Use the Command 'Sudo' in Windows

Use the Command Sudo in Windows

If you've ever used Linux or know someone who uses Linux, then you probably know the sudocommand. This command is an essential element in almost all Linux distributions, it allows to run a command as a different user, with the right to administrator, including the root user. On some Linux distributions, you can log in as ROOT using the su command, but is not very advisable... it is even considered as very risky and never do.
In fact, it's so dangerous that it is disabled by default on most distributions like Ubuntu Linux. Instead, you are required to use the sudo command if you want to run a command as root.
And Windows then? Well, unfortunately, most people are connected to Windows with an administrator account, which is the same as a Linux root account. However, Microsoft has attempted to mitigate the harmful effects to be logged in as an administrator with UAC (User Account Control).
Like this even if the user has administrative privileges, applications running under this account will not these privileges, unless it be manually authorized by the user. This allows to restrict access to the system for malware.
While Linux users have the sudo command, what is wrong with Windows users? There - he of the alternatives they can use to execute commands with elevated privileges? There - he a sudo for Windows command? of course there is, otherwise I wouldn't be writing this post 😉 here are two methods to use sudo on Windows:

The Runas command:

Windows has the runas command, which is the direct counterpart of sudo on Linux. The use of this command allows you to run a script, a program or a command as a different user or as an administrator. The full syntax of the runas command is:
runas [{/profile|/no profile}] [/env] [/netonly] [/smart card] [/showtrustlevels] [/trustlevel] /user:UserAccountName program
Example: If you want to open an administrator command prompt you can type the following command:
runas /noprofile /user:Administrator cmd
runas windows
/noprofile does not load the profile of the current user. You can remove it if you need to access environment variables. For example: If you want to open a text file using Notepad with administrator privileges, you can use this command:
runas /user:Administrator “notepad my_file.txt”
Note that when you use the runas command to install a program or change a few settings, etc., changes will be made on the user account that you use with command. For example, let's say you have the user X who is a normal user and user Y who is a Director. If you connect to X, then do a runas by using the credentials of the administrator (Y), the changes will be made to the administrator settings (Y), and not the user X.
This is not the case with the second method:

Sudo Windows - PowerShell:

For this second method we will use a program PowerShell which will allow you to launch programs Windows Form or console as an administrator using the command sudo, just like on linux.
This program is called «Sudo for Windows» To install open PowerShell and run the following 3 commands:
iex (new-object net.webclient).downloadstring(‘https://get.scoop.sh’)
set-executionpolicy unrestricted -s cu -f
scoop install sudo
If everything goes smoothly, you should have something similar to the screenshot below:
installer sudo sous windows
Now all you have to do to launch a program in sudo under Windows is to add small sudo before your order.
sudo votre_commande
Let's take as an example the creation of a file in a system directory using the mkdir with and without the sudo command.
sudo windows
That's all, the only small problem here is that to each command with sudo execution, control UAC window will appear asking you if you want to run the command as an admin, and you must each time click on Yes. But even with this slight inconvenience, the benefits are worth it.
I hope you enjoyed this tutorial and that it will be useful to the next!

No comments

Powered by Blogger.