Selamat means safe. On its own it is what you say when someone has survived something, or achieved something: selamat! is also how you say congratulations.
Attached to a time of day, it becomes a greeting. Learn the word once and four greetings come with it.
The four
Selamat pagi ‘good morning’ until around eleven
Selamat siang ‘good midday’ from eleven to about three
Selamat sore ‘good afternoon’ from three until dark
Selamat malam ‘good evening’ after dark
The one English does not have
Siang is the gap. English jumps from morning to afternoon at noon; Indonesian puts a whole word in the middle of the day, roughly eleven to three, which is exactly when the sun is worst and nobody wants to be outside.
Foreigners reach for pagi at two in the afternoon because their own language has no siang. It is the single most common greeting mistake, and it marks you as new. Indonesians find it charming precisely once.
Shortening them
In practice people drop selamat constantly. Pagi! on its own is warm and normal between people who know each other, the way “morning!” works in English.
What the book says: Selamat pagi, Bapak. What you’ll hear: Pagi, Pak!
Malam does double duty
Selamat malam covers both hello and goodbye after dark. If you specifically want to wish someone a good night’s sleep, that is selamat tidur, literally ‘safe sleep’, and you only say it to someone actually going to bed.