Listen at every opportunity to all different genres of music--country, rock, R&B and blues. Listen especially to "hit" songs, songs that have a trademark riff or chorus. Figure out what these songs have in common and how they are different.
Get comfortable with how the guitar works as an instrument. Anyone can create a riff, but you must have a working knowledge of music and the guitar. You don't have to be a virtuoso, but you must have a fundamental idea of the basic chords and scales.
Use what you have listened to, what you have learned and your own musical creativity. As a general rule, most "catchy" riffs or the ones that become hit songs are simple. If the chords are the "hook," or part of the song that is repeated that the listener keeps hearing, they should be a simple progression. This means usually at least two chords, many times three chords. In many of today's hit songs, there are four chords that make the song. Any more than this and the song loses its compactness. As listeners, most people seem to be more attuned to short, simple riffs as opposed to complicated, drawn-out riffs. Keep it short, sweet and repetitive. After you have this down, if you want to get more complicated, you can.
Often the riffs that are most recognizable are at the beginning of the song. Other times it's the chorus that catches your attention. This is your choice as a creative artist. A riff can be either a pattern of chords, such as "Smoke on the Water" or a pattern of individual notes, as in "Layla." The critical aspect of this is that whatever you choose, it should be a repeating pattern.
Create the rest of the song, for a riff without the rest of the song is incomplete. Deciding if your riff is a verse, chorus or introduction is all part of the arrangement of a song. Some of the greatest songs likely have been rearranged so that the signature riff is the most prominent part of the song.
Practice, practice and practice. There is no magic pill that can give you the skills or creativity to create a hit riff, but almost anyone can create something to be proud of, with practice. Repetition will help with recognizing what chords, notes and scales work best together for whatever kind of music you play.