The brightest galactic X-ray sources are X-ray binary systems. In an X-ray binary, a compact object (i.e. black hole, neutron star or white dwarf -- see the Life Cycle of Stars section for more, especially Star Life & Death) accretes matter from a companion. Throughout this page, I'll refer to the compact object and it's companion...the companion always refers to the "other" object. There are two types of X-ray binaries, and the mass of the companion dictates the type of accretion that occurs.
If the companion is a low mass star (M less than Msun; where Msun = 2 x 1030 kg, the mass of the Sun), the accretion occurs through Roche lobe overflow (I'll explain this in a second) and the system is termed a Low Mass X-ray Binary (LMXB). In this case, the companion star becomes, literally, too big for its britches.
The Roche lobe of an object is the volume around the object, inside which material is gravitationally bound to that object. The point between Roche lobes in a binary system is where the gravity from the companion is equal to the gravity from the compact object. It often happens that this point is close to the companion's surface, so that some of the material in the star's outer edges (on the edge of the Roche lobe) finds itself no longer bound to the star. This "unbound" material flows from the companion to the compact object.
The material that is "stripped" off of the companion will tend to form a disk around the compact object, rather than falling directly in. Why? The material has angular momentum from orbiting the companion star. Since that angular momentum can't just disappear, the material will orbit the compact object, forming an accretion disk. The material in the accretion disk will spiral in to the compact object, losing that angular momentum as it goes. This process heats up the material in the disk to temperatures of more than a million degrees! It is this hot material that emits X-rays (justifying the name "X-ray binary"). The animation below follows the path of one "parcel" of material from the time it crosses into the compact object's Roche lobe, into the accretion disk and finally onto the compact object.
Realistically, the material that is stripped off of the low-mass companion spends a lot more time in the accretion disk than the animation indicates. I shortened the time to make the animation a downloadable size. Also, there would be more of a constant stream of material from the companion, rather than just one parcel at a time.
The first extrasolar X-ray source observed was Scorpius X-1 (aka Sco X-1), which is a low-mass X-ray binary system. It was discovered during a rocket flight, which was designed to look for X-ray emission from the moon. No emission from the moon was discovered at that time, but Sco X-1 was close enough to the moon that the telescope detected its X-ray emission.
If the companion is a high mass star (M greater than 10Msun), the accretion occurs through capture of the companion’s stellar wind and the system is called a High Mass X-ray Binary (HMXB). The high mass companion sheds mass through a wind. This wind flows isotropically (equally in all directions) from the companion, so a portion of it cannot help but run into the compact object. The material that runs into the compact object releases some of its potential energy as X-rays.
The compact object and the companion, in the above animation, would really be orbiting each other. However, since the wind from the companion is being emitted isotropically (in all directions), some of the wind is always running into the compact object.
The Vela X-1 binary system is composed of a neutron star orbiting an OB supergiant (a class of giant star). The neutron star is an X-ray pulsar. By looking at the X-ray pulses in conjunction with the optical (visible light) lines from the OB star, we can make accurate estimates of the masses of both stars in the binary. In this case, the neutron star appears to have a mass of 1.77 M sun, and the OB star has a mass of 23 Msun.