How to Connect to Your VDS Server via SSH (Complete Guide)
Step-by-step SSH connection guide for Linux VDS: PuTTY, Terminal, key-based authentication, Path Panel firewall rules, and security best practices.
Complete guide to systemctl commands, service unit files, creating custom services, journalctl log monitoring, and systemd troubleshooting on Linux servers.
Systemd is the init system and service manager used by most modern Linux distributions. On Ubuntu, Debian, CentOS, AlmaLinux, and RHEL, systemd handles everything from system startup to service management. This guide covers systemctl commands, unit files, and creating custom services.
Systemd is the first process started after the Linux kernel (PID 1). Its responsibilities include:
Systemd replaced the older SysV init system. While /etc/init.d/ scripts still work, systemd unit files are now the preferred approach.
# View service status
sudo systemctl status nginx
# Check if service is running
sudo systemctl is-active nginx
# Check if service is enabled
sudo systemctl is-enabled nginx
# List all running services
sudo systemctl list-units --type=service --state=running
# List failed services
sudo systemctl list-units --type=service --state=failed
# Start a service
sudo systemctl start nginx
# Stop a service
sudo systemctl stop nginx
# Restart a service (stop + start)
sudo systemctl restart nginx
# Reload service configuration without stopping
sudo systemctl reload nginx
# Reload if possible, otherwise restart
sudo systemctl reload-or-restart nginx
# Enable service to start at boot
sudo systemctl enable nginx
# Start service and enable at boot
sudo systemctl enable --now nginx
# Disable automatic startup
sudo systemctl disable nginx
# Stop service and disable
sudo systemctl disable --now nginx
# Mask a service (prevent it from being started)
sudo systemctl mask nginx
# Unmask a service
sudo systemctl unmask nginx
Unit files define how systemd manages services. There are two main locations:
/lib/systemd/system/ — Unit files installed by package manager/etc/systemd/system/ — Unit files created/customized by system administrator# View a service's unit file
sudo systemctl cat nginx
# Find the unit file location
sudo systemctl show nginx --property=FragmentPath
# List all unit files
sudo systemctl list-unit-files --type=service
A .service unit file has three main sections:
[Unit]
Description=Nginx HTTP Server
After=network.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[Unit] Section:
Description: Service descriptionAfter: Which services this should start afterRequires: Mandatory dependenciesWants: Optional dependencies[Service] Section:
Type: Service type (simple, forking, oneshot, notify, dbus)ExecStart: Command to start the serviceExecStop: Command to stop the serviceRestart: Restart policyUser/Group: User to run the service as[Install] Section:
WantedBy: Which target this belongs toCreating a systemd service for your own application is straightforward.
# Create the unit file
sudo nano /etc/systemd/system/myapp.service
[Unit]
Description=My Node.js Application
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/myapp
ExecStart=/usr/bin/node /var/www/myapp/app.js
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal
Environment=NODE_ENV=production
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
# Reload systemd to recognize the new unit file
sudo systemctl daemon-reload
# Start and enable the service
sudo systemctl enable --now myapp
# Check status
sudo systemctl status myapp
| Type | Description | Use Case |
|---|---|---|
simple | Main process runs directly | Node.js, Python |
forking | Main process forks and exits | Nginx, Apache |
oneshot | One-time task | Startup scripts |
notify | Sends notification when ready | Systemd-aware apps |
Systemd's logging system journald collects all service logs centrally.
# View all logs
sudo journalctl
# View logs for a specific service
sudo journalctl -u nginx
# View last 50 lines
sudo journalctl -u nginx -n 50
# Follow logs in real time
sudo journalctl -u nginx -f
# Logs from the last hour
sudo journalctl -u nginx --since "1 hour ago"
# Specific date range
sudo journalctl -u nginx --since "2024-01-01" --until "2024-01-02"
# Only error logs
sudo journalctl -u nginx -p err
# Boot logs
sudo journalctl -b
# Check log disk usage
sudo journalctl --disk-usage
# Clean up old logs (older than 2 weeks)
sudo journalctl --vacuum-time=2weeks
# Get detailed status
sudo systemctl status myapp -l
# Check recent logs
sudo journalctl -u myapp -n 100 --no-pager
# Validate unit file
sudo systemd-analyze verify /etc/systemd/system/myapp.service
# Check dependency issues
sudo systemctl list-dependencies myapp
# Always run this after modifying a unit file
sudo systemctl daemon-reload
# Check restart policy
sudo systemctl show myapp --property=Restart
# Reset the failure counter
sudo systemctl reset-failed myapp
When developing a service, start with Type=simple and Restart=on-failure. Optimize other settings once the service is stable.
Systemd timers offer a modern alternative to cron jobs.
# Create a timer unit file
sudo nano /etc/systemd/system/backup.timer
[Unit]
Description=Daily Backup Timer
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
# Enable the timer
sudo systemctl enable --now backup.timer
# List all timers
sudo systemctl list-timers
Systemd is the cornerstone of modern Linux server management. Learning systemctl commands and unit file structure lets you reliably manage services on your server. On REXE servers, you can create custom services to ensure your applications automatically start after system reboots.
'enable' marks the service to start automatically at boot but does not start it immediately. 'start' starts the service right away but won't auto-start on reboot. To do both at once, use 'systemctl enable --now service-name'.
After modifying a unit file, always run 'sudo systemctl daemon-reload'. Then restart the service with 'sudo systemctl restart service-name'. Without daemon-reload, changes won't take effect.
Use 'sudo journalctl -u service-name -f' for real-time log following. Add '-n 100' to see the last 100 lines first. Use '-p err' to filter only error messages.
Start with 'sudo systemctl status service-name -l' for detailed status. Then check 'sudo journalctl -u service-name -n 50' for recent logs. Validate the unit file with 'sudo systemd-analyze verify /etc/systemd/system/service.service'.
Systemd timers are more modern and integrated: they log to journald, support dependency management, and are easy to monitor with 'systemctl list-timers'. For simple tasks, cron is fine. For tasks with service dependencies or that need log tracking, prefer systemd timers.
Step-by-step SSH connection guide for Linux VDS: PuTTY, Terminal, key-based authentication, Path Panel firewall rules, and security best practices.
Complete guide to connecting to Windows Server VDS via Remote Desktop (RDP): setup steps, NLA security, Path Panel firewall rule, and troubleshooting tips.
Step-by-step guide to changing your VDS server OS via REXE panel: backup tips, supported Linux distributions and Windows Server versions explained.