Get ID from user and group in Linux

Hi everyone,

Sometimes it handy to deal with id’s instead of actual names. It makes your commands shorter.
So if you ever need to get the id’s of one user or a group in Linux, here’s the commands to run:

– id -u USERNAME – will give you the USERNAME ID;
– id -a USERNAME – will give, not only the ID of the user, but also all the groups the user is part of;
– id -g USERNAME – will give the ID of the user’s primary group;
– id -G USERNAME – will give you the ID of all groups the user is a member of;

If you just want to know the id of a group, the just run:

cat /etc/group | grep GROUPNAME

The third item of the colon(:) separated string is the group ID.

And there you have it.
Now you can find out every user and group ID’s.

Enjoy.

Windows 8 and Windows Server 2012 – Problems with activation

The new versions of Windows are out, and with them come a whole new set of little challenges.

So let’s start from the beginning.

You just installed your new OS and you get a DNS error when trying to activate it.

Well, here’s how you go about it.

 

Open a command line with Administrative privileges and type:

slmgr.vbs /ipk followed by your serial key. Press enter and there you have it. A brand new activated Windows.

Enjoy.

How do I find out what are my drive letters in Windows Core?

So you just installed you Windows Server Core and you want to identify your disk drives. Or maybe you’ve plugged a USB disk to copy some files and you don’t know the drive letter.

Since there is no explorer in Server Core you will have to use diskpart. Diskpart is a utility to manage disk drives and has been available since Windows Vista and replaced the old fdisk. You’ve surely used diskpart in it’s GUI version of Disk Management, so now you just have to get used to it in a command line.

So to find out your disk drive letter in Windows Server Core just type diskpart and then list volume. This will give a list of disks and their drive letters.

 

 

To leave diskpart just type exit. If you want to discover more about diskpart type help.

 

Linux – What distro am I using?

Let’s say you’ve been given access to a Linux machine (SSH or any other plain terminal), but you have no idea of version or distro you are using.

Even though Linux is mostly the same, there are some diferences. So, to find out, here’s a couple of commands that can be usefull.

head -n1 /etc/issue 
and
uname -a
Note that the first command can be deceiving. /etc/issue is a text file that can be altered.
Enjoy.

Killing a Windows Service that seems to hang on “Stopping”

When a service hangs in a “Stopping” state, a SysAdmin can kill the service using this procedure:

  1. Open a command-prompt, in Administrator Mode, and query the service (e.g. the BITS service)
    sc queryex BITS
  2. This will give you the following information:

NOTE: In the STATE field, it should mention stopping.

  1. In the sc queryex results you can find the process identifier (PID). With it, you can kill the associated process either by using the task manager or by using taskkill:

taskkill /PID 420 /F

The /F flag is needed to force the process kill.

Another way to go about it is to identify the Displayname of the service, using the services console   (services.msc):

and use:

taskkill /IM “Displayname” /F

This is very useful for emergencies but you shouldn’t use it on a regular basis (use it as a last chance to solve the problem or to avoid the need of a reboot in an exceptional situation).

More info on sc.exe can be found via http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sc.mspx.

 

Windows Server Core – What now?

So you just installed you first Windows Server Core and you don’t really know what to do now.
Well, here’s some help. To configure the basics of your brand new server you can use the command sconfig. It will show you a nice Powershell menu to help you out.

Now you can configure the basic settings for your server without feeling lost.

Who’s listening

When you want to find out what port is that service running on there’s a nice command to help you.

It’s called netstat and it’s available on Windows and Linux.

Here’s a couple of usage examples:

  • Find who’s connected to your port 25 (Usually SMTP Server).
  • Windows: netstat -ano | findstr :25 | findstr ESTABLISHED
  • Linux: netstat -ano | grep :25 | grep ESTABLISHED
  • Find what port’s are listening.
  • Windows: netstat -ano |  findstr LISTENING
  • Linux: netstat -ano | grep LISTENING

You can use multiple combinations of this command with regular expression filters to get what you need. This is a great tool to find what ports are being used and from where.

Enjoy.

Linux – Set your home folder default permissions (umask)

When you create a file or directory under Linux, the file/directory will have a default set of permissions.

Usually the system defaults may be less then secure. For example, if a text file has 666 permissions, it grants read and write permission to everyone, or, if a directory has 777 permissions, grants read, write, and execute permission to everyone.

If you need more security/privacy in your home folder, you can set up the default permissions by editing the .profile or the .bashrc files with your favorite text editor.

After opening the file, look for something like umask 022 (it may be commented out with the # sign), and change the value for umask 077.

If you want to play around with permissions, here’s what you need to have in mind.

In *nix systems the permissions are always set for user, group and others, so if you set your umask to 077 you will end up with the following permissions:

Owner – Read, Write, Execute

Group – No Permissions

Others – No Permissions

Here’s a little guide for octal permissions in *nix.

Octal value : Permission

0 : read, write and execute

1 : read and write

2 : read and execute

3 : read only

4 : write and execute

5 : write only

6 : execute only

7 : no permissions

 

Delete Failed DCs from Active Directory

S#!” Happens!!!
The hardware failed, some software installation killed you DC or you just formatted it without demoting it first.
This will leave the entries in you Active Directory database and will eventually give you some trouble.
So, to remove this information all you need is to open a command line and be a member of the Enterprise Admins universal group.
So, open a command line and type ntdsutil. This will give you a new prompt.
At the ntdsutil: prompt, type metadata cleanup and press Enter.
At the metadata cleanup: prompt, type connections and press Enter.
At the server connections: prompt, type connect to server <servername>, where <servername> is the domain controller (any functional domain controller in the domain) from which you plan to clean up the metadata of the failed domain controller. Press Enter.
Type quit and press Enter to return you to the metadata cleanup: prompt.
Type select operation target and press Enter.
Type list domains and press Enter. This lists all domains in the forest with a number associated with each.
Type select domain <number>, where <number> is the number corresponding to the domain in which the failed server was located. Press Enter.
Type list sites and press Enter.
Type select site <number>, where <number> refers to the number of the site in which the domain controller was a member. Press Enter.
Type list servers in site and press Enter. This will list all servers in that site with a corresponding number.
Type select server <number> and press Enter, where <number> refers to the domain controller to be removed.
Type quit and press Enter. The Metadata cleanup menu is displayed.
Type remove selected server and press Enter.

You will receive a warning message. Read it, and if you agree, press Yes.

At this point, Active Directory confirms that the domain controller was removed successfully. If you receive an error that the object could not be found, Active Directory might have already removed from the domain controller.

Type quit, and press Enter until you return to the command prompt.

After you just need to confirm if the object was completely removed from Active Directory.

To remove the failed server object from the sites

In Active Directory Sites and Services, expand the appropriate site.

If the object exists, delete the server object associated with the failed domain controller, then open Active Directory Users and Computers go to the Domain Controllers container and, again, if exists, delete the computer object associated with the failed domain controller

You might get a warning asking you if you want to delete the server object without performing a DCPROMO operation (which, of course, you cannot perform). Just select “This DC is permanently offline…” and click on the Delete button.AD will display another confirmation window. If you’re sure that you want to delete the failed object, click Yes.

All that’s missing now is the DNS entries. So open the DNS mmc console.

In the DNS snap-in, expand the zone that is related to the domain from where the server has been removed.
Remove the CNAME record in the _msdcs.root domain of forest zone in DNS. You should also delete the HOSTNAME and other DNS records.
If you have reverse lookup zones, also remove the server from these zones.
Just a couple of word of advice.
Using the ntdsutil utility incorrectly may result in partial or complete loss of Active Directory functionality.
If the Domain Controller was responsible for any FSMO, don’t forget to seize the roles first.