Configure various keys and API credentials for your FiveM server. Proper key management is essential for security and functionality.
The FiveM license key is required to run a server. It’s obtained from the Cfx.re Keymaster and identifies your server instance.
xxxxx-xxxxx-xxxxx-xxxxx-xxxxx)Method 1: Environment Variable (Recommended)
# Set environment variable
export sv_licenseKey="your-license-key-here"
# Or add to ~/.bashrc or ~/.zshrc for persistence
echo 'export sv_licenseKey="your-license-key-here"' >> ~/.bashrc
source ~/.bashrcMethod 2: server.cfg
# server.cfg
set sv_licenseKey "your-license-key-here"Method 3: Systemd Service (Production)
# /etc/systemd/system/fivem.service
[Unit]
Description=FiveM Server
After=network.target
[Service]
Type=simple
User=fivem
WorkingDirectory=/opt/fivem
Environment="sv_licenseKey=your-license-key-here"
ExecStart=/opt/fivem/run.sh
Restart=always
[Install]
WantedBy=multi-user.targetCheck server console for license validation:
[INFO] License key validated successfullyCauses:
Solutions:
Verify Key Format:
# Check key format (should be 5 groups of 5 characters)
echo $sv_licenseKey
# Should output: xxxxx-xxxxx-xxxxx-xxxxx-xxxxxCheck Key Status:
Regenerate Key:
Solution:
Causes:
Solution:
# Verify environment variable is set
echo $sv_licenseKey
# Check server.cfg
grep -i "license" /opt/fivem/server.cfg
# Test with explicit key
./fxserver +set sv_licenseKey "your-key-here"Steam API keys enable Steam authentication and player verification on your server.
example.com)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)Method 1: server.cfg
# server.cfg
set steam_webApiKey "your-steam-api-key-here"Method 2: Environment Variable
export steam_webApiKey="your-steam-api-key-here"# server.cfg
set steam_webApiKey "your-steam-api-key-here"
# Require Steam authentication (optional)
set sv_enforceGameBuild 2699-- server.lua
AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)
local source = source
local identifiers = GetPlayerIdentifiers(source)
local steamId = nil
for _, identifier in ipairs(identifiers) do
if string.match(identifier, 'steam:') then
steamId = identifier
break
end
end
if not steamId then
setKickReason('Steam authentication required')
CancelEvent()
return
end
-- Use Steam ID for player identification
print('Player connecting with Steam ID: ' .. steamId)
end)-- server.lua
local function GetSteamProfile(steamId)
local apiKey = GetConvar('steam_webApiKey', '')
if apiKey == '' then
return nil
end
-- Extract Steam64 ID from identifier
local steam64 = string.gsub(steamId, 'steam:', '')
steam64 = tonumber(steam64, 16) -- Convert hex to decimal
-- Make API request (requires HTTP library)
-- This is a simplified example
return {
steamId = steam64,
profileUrl = 'https://steamcommunity.com/profiles/' .. steam64
}
endSolutions:
Verify Key Format:
# Check key is 32 characters
echo ${#steam_webApiKey}
# Should output: 32Check Key Status:
Regenerate Key:
Causes:
Solutions:
-- Add fallback for Steam authentication
AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)
local source = source
local identifiers = GetPlayerIdentifiers(source)
local hasSteam = false
for _, identifier in ipairs(identifiers) do
if string.match(identifier, 'steam:') then
hasSteam = true
break
end
end
if not hasSteam then
-- Optional: Allow non-Steam players
-- Or require Steam
setKickReason('Steam authentication required')
CancelEvent()
end
end)Discord bot tokens enable Discord integration for your server, including player verification, chat bridges, and admin notifications.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)botMethod 1: Resource Configuration
Most Discord resources use their own config files:
-- discord-bot/config.lua
Config = {
token = "your-discord-bot-token-here",
guildId = "your-discord-server-id",
channelId = "your-channel-id"
}Method 2: Environment Variable
export DISCORD_BOT_TOKEN="your-discord-bot-token-here"Method 3: server.cfg (if resource supports it)
# Some resources may support this
set discord_botToken "your-discord-bot-token-here"// discord-bot/index.js
const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
})
client.once('ready', () => {
console.log('Discord bot is ready!')
})
client.on('messageCreate', (message) => {
if (message.content === '!serverstatus') {
// Query FiveM server status
message.reply('Server is online!')
}
})
client.login(process.env.DISCORD_BOT_TOKEN)-- server.lua
local discordWebhook = "https://discord.com/api/webhooks/your-webhook-url"
-- Send chat message to Discord
RegisterCommand('discord', function(source, args, rawCommand)
local message = table.concat(args, ' ')
local playerName = GetPlayerName(source)
-- Send to Discord webhook
PerformHttpRequest(discordWebhook, function(err, text, headers)
-- Handle response
end, 'POST', json.encode({
content = string.format('%s: %s', playerName, message)
}), {
['Content-Type'] = 'application/json'
})
end, false)-- server.lua
local discordWebhook = "https://discord.com/api/webhooks/your-webhook-url"
AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)
local source = source
local identifiers = GetPlayerIdentifiers(source)
-- Send join notification to Discord
PerformHttpRequest(discordWebhook, nil, 'POST', json.encode({
embeds = {{
title = "Player Joining",
description = string.format("**%s** is connecting to the server", name),
color = 3066993 -- Green
}}
}), {
['Content-Type'] = 'application/json'
})
end)
AddEventHandler('playerDropped', function(reason)
local source = source
local name = GetPlayerName(source)
-- Send leave notification to Discord
PerformHttpRequest(discordWebhook, nil, 'POST', json.encode({
embeds = {{
title = "Player Left",
description = string.format("**%s** left the server\nReason: %s", name, reason),
color = 15158332 -- Red
}}
}), {
['Content-Type'] = 'application/json'
})
end)Solutions:
Verify Token Format:
# Discord bot tokens are 59+ characters
echo ${#DISCORD_BOT_TOKEN}
# Should output: 59 or moreCheck Token Status:
Reset Token:
Solution:
Re-invite bot with correct permissions:
Check bot role in Discord server:
Solution:
Best Practice: Always use environment variables for sensitive keys.
# Create .env file (never commit this!)
cat > /opt/fivem/.env << EOF
sv_licenseKey=your-license-key
steam_webApiKey=your-steam-key
DISCORD_BOT_TOKEN=your-discord-token
EOF
# Secure the file
chmod 600 /opt/fivem/.env
chown fivem:fivem /opt/fivem/.env# Load .env in your startup script
#!/bin/bash
set -a
source /opt/fivem/.env
set +a
./fxserver# /etc/systemd/system/fivem.service
[Unit]
Description=FiveM Server
After=network.target
[Service]
Type=simple
User=fivem
WorkingDirectory=/opt/fivem
EnvironmentFile=/opt/fivem/.env
ExecStart=/opt/fivem/run.sh
Restart=always
[Install]
WantedBy=multi-user.targetRegularly rotate keys to maintain security:
Generate New Key:
Update Configuration:
# Update .env file
nano /opt/fivem/.env
# Or update server.cfg
nano /opt/fivem/server.cfgTest New Key:
# Restart server
systemctl restart fivem
# Check logs for errors
journalctl -u fivem -fRevoke Old Key:
# Secure server.cfg
chmod 600 /opt/fivem/server.cfg
chown fivem:fivem /opt/fivem/server.cfg
# Secure .env file
chmod 600 /opt/fivem/.env
chown fivem:fivem /opt/fivem/.env# .gitignore
server.cfg
.env
*.key
*.token
config.luaCreate a script to validate all keys:
#!/bin/bash
# validate-keys.sh
echo "Validating FiveM keys..."
# Check license key
if [ -z "$sv_licenseKey" ]; then
echo "❌ License key not set"
else
echo "✅ License key is set"
fi
# Check Steam API key
if [ -z "$steam_webApiKey" ]; then
echo "❌ Steam API key not set"
else
echo "✅ Steam API key is set"
fi
# Check Discord token
if [ -z "$DISCORD_BOT_TOKEN" ]; then
echo "❌ Discord bot token not set"
else
echo "✅ Discord bot token is set"
fi