How To Restart Linux Server From Ssh – Using Putty Ssh Client

From an SSH session, you can restart a Linux server by typing sudo reboot, though it will disconnect you immediately. This quick command is the most common way to handle a remote reboot, but understanding how to restart Linux server from SSH properly involves more than just typing a single line. Whether you’re managing a production server or a home lab, knowing the safe and reliable methods prevents data loss and downtime.

In this guide, you’ll learn multiple ways to restart your Linux server via SSH, from simple commands to scheduled reboots. We’ll cover what happens during a restart, how to avoid common mistakes, and what to do if the server doesn’t come back online. By the end, you’ll feel confident handling remote reboots like a sysadmin.

Why Restart A Linux Server From Ssh?

Restarting a server remotely is a common task for administrators. You might need to apply kernel updates, fix a stuck service, or clear memory leaks. Doing it from SSH saves you from having to physically access the machine.

When you restart via SSH, you’re sending a signal to the init system (like systemd or SysVinit) to begin the shutdown and reboot sequence. The server will close all processes, unmount filesystems, and then power cycle. Your SSH session will drop immediately after the command executes.

Common Reasons For A Remote Reboot

  • Installing new kernel updates that require a reboot
  • Resolving system hangs or unresponsive services
  • Applying configuration changes that need a fresh boot
  • Clearing temporary files or memory fragmentation
  • Testing high-availability failover setups

Prerequisites For Restarting Via Ssh

Before you run any reboot command, make sure you have the right access. You need SSH access to the server and sudo privileges. Without sudo, you’ll get a permission denied error.

Also, ensure you have a backup connection method. If the reboot fails, you might need console access via a web panel or IPMI. This is especially important for production servers.

Check Your Sudo Access

Test your sudo privileges by running a simple command like sudo whoami. If it returns “root,” you’re good to go. If not, contact your system administrator to grant you the necessary permissions.

Save Your Work

Before restarting, save any open files or running processes. If you have unsaved data in a text editor or database, it could be lost. Use screen or tmux to keep sessions alive if needed.

How To Restart Linux Server From Ssh: Step-By-Step Methods

Now let’s get into the actual commands. There are several ways to restart a Linux server from SSH, each with slight differences. Choose the one that fits your situation.

Method 1: Using The Reboot Command

The simplest method is the reboot command. It’s available on almost all Linux distributions.

  1. Log into your server via SSH: ssh user@server-ip
  2. Type sudo reboot and press Enter
  3. You’ll be prompted for your password if you haven’t used sudo recently
  4. The server will begin the reboot process and your SSH session will disconnect

That’s it. The server will restart and come back online within a minute or two, depending on hardware and services.

Method 2: Using The Shutdown Command

The shutdown command gives you more control. You can schedule a reboot or add a delay.

To reboot immediately: sudo shutdown -r now

To reboot after 5 minutes: sudo shutdown -r +5

To cancel a scheduled reboot: sudo shutdown -c

The -r flag tells the system to reboot instead of halting. The time argument can be in minutes or a specific time like “23:00”.

Method 3: Using Systemctl (For Systemd Systems)

Most modern Linux distributions use systemd. The systemctl command is the preferred way to manage services and reboots.

To reboot: sudo systemctl reboot

This command does the same as sudo reboot but uses the systemd interface. It’s more explicit and works well in scripts.

Method 4: Using Init Command (Older Systems)

On older systems using SysVinit, you can use the init command with runlevel 6.

Type: sudo init 6

Runlevel 6 is the standard reboot runlevel. This method still works on many legacy servers.

What Happens When You Restart A Linux Server?

Understanding the reboot process helps you troubleshoot if something goes wrong. Here’s a simplified breakdown:

  1. The init system receives the reboot signal
  2. All running processes are sent a SIGTERM to shut down gracefully
  3. After a timeout, remaining processes get SIGKILL
  4. Filesystems are unmounted
  5. The kernel performs a system reset
  6. The BIOS/UEFI runs POST and loads the bootloader
  7. The kernel loads and starts the init system again
  8. Services and daemons start up
  9. SSH service becomes available again

Most of this happens in under 60 seconds on modern hardware. If your server has many services, it might take longer.

How To Avoid Common Reboot Mistakes

Restarting a server seems simple, but small mistakes can cause big problems. Here are pitfalls to avoid.

Forgetting To Notify Users

If you’re rebooting a production server, let users know beforehand. Send a message using wall or a broadcast tool. Unexpected downtime frustrates people.

Rebooting During Peak Hours

Schedule reboots during low-traffic periods. Use the shutdown -r command with a time delay to plan ahead.

Not Checking For Running Processes

Before rebooting, check for critical processes that might need manual intervention. Use ps aux or top to see what’s running.

Ignoring Filesystem Checks

If your server has filesystem issues, a reboot might trigger a forced fsck. This can delay the restart significantly. Run sudo fsck -n to check before rebooting.

How To Reboot If The Server Is Unresponsive

Sometimes SSH becomes unresponsive, and you can’t run commands. In these cases, you need alternative methods.

Using Out-Of-Band Management

Many servers have IPMI, iDRAC, or iLO interfaces. These allow you to send a reboot command even if the OS is frozen. Log into the management interface and select “Power Cycle” or “Reset”.

Using A Web Hosting Control Panel

If you’re using a VPS or cloud server, your provider likely has a web panel. Look for a “Reboot” or “Restart” button. This sends a hardware-level reset.

Using The Magic SysRq Key

If you have physical or console access, you can use the Magic SysRq key combination. Press Alt+SysRq+R then Alt+SysRq+B to reboot safely. This works even when the kernel is partially hung.

How To Test If The Server Came Back Online

After issuing the reboot command, you’ll lose your SSH connection. Wait a minute, then try to reconnect.

Use ssh user@server-ip again. If it connects, the reboot was successful. If not, wait another 30 seconds and try again.

You can also ping the server: ping server-ip. If you get replies, the network stack is up.

Check System Logs After Reboot

Once you’re back in, check the system logs to confirm the reboot went smoothly. Run journalctl -b -1 to see logs from the previous boot. Look for errors or warnings.

Also check uptime: uptime. This shows how long the server has been running since the last reboot.

How To Schedule A Reboot In Advance

Sometimes you need to reboot at a specific time, like during a maintenance window. The shutdown command handles this easily.

To reboot at 2:00 AM: sudo shutdown -r 02:00

To reboot in 30 minutes: sudo shutdown -r +30

You can also use at or cron for more complex scheduling. For example, to reboot every Sunday at 3 AM, add this to crontab:

0 3 * * 0 /sbin/shutdown -r now

Be careful with automated reboots. Test them first in a non-production environment.

What To Do If The Server Doesn’t Come Back

Occasionally, a server fails to reboot. This can be due to hardware failure, corrupted kernel, or bootloader issues. Here’s what to check.

Check Network Connectivity

First, verify that the server is reachable on the network. Ping it from another machine. If ping fails, the issue might be network-related.

Use Console Access

If you have out-of-band management, log into the console. You’ll see the boot process in real time. Look for error messages like “Kernel panic” or “No bootable device”.

Boot Into Recovery Mode

If the server boots but doesn’t start SSH, you might need to boot into single-user mode. From the console, interrupt the boot process and edit the kernel parameters. Add “single” or “1” to the end of the kernel line.

Once in single-user mode, you can fix configuration issues or reinstall the kernel.

Contact Your Hosting Provider

If you’re using a cloud or VPS service, contact support. They can often force a reboot or provide console access. Most providers have 24/7 support for such issues.

Best Practices For Remote Reboots

To minimize risk, follow these best practices every time you reboot a remote server.

  • Always use sudo to avoid permission issues
  • Notify users and stakeholders before rebooting
  • Schedule reboots during low-traffic periods
  • Keep a backup of critical configuration files
  • Test the reboot process in a staging environment first
  • Monitor the server after reboot to ensure all services start
  • Document the reboot procedure for your team

Common Errors And How To Fix Them

Even experienced admins run into errors. Here are some common ones and their solutions.

Permission Denied

If you get “Permission denied” when trying to reboot, you don’t have sudo access. Ask your admin to add you to the sudoers file. Alternatively, use su - to switch to root if you have the password.

Command Not Found

If reboot or shutdown isn’t found, your PATH might be misconfigured. Try using the full path: /sbin/reboot or /usr/sbin/shutdown.

System Is Already Rebooting

If you see “System is going down for reboot,” another user already initiated a shutdown. Wait for it to complete or cancel it with sudo shutdown -c.

Failed To Start Reboot

This error often indicates a systemd issue. Try sudo systemctl reboot --force to bypass normal shutdown procedures. Use this only as a last resort.

How To Restart Linux Server From Ssh With A Script

If you reboot servers frequently, automate the process with a script. Here’s a simple bash script that reboots and logs the event.

#!/bin/bash
echo "Rebooting server at $(date)" >> /var/log/reboot.log
sudo shutdown -r now

Save this as reboot.sh, make it executable with chmod +x reboot.sh, and run it when needed. You can also schedule it with cron for automatic reboots.

Security Considerations

Rebooting via SSH is generally safe, but there are security implications. Ensure your SSH keys are secure and that only authorized users have sudo access.

If you’re rebooting after a security patch, verify that the patch was applied correctly. Check the package manager logs to confirm.

Also, consider using two-factor authentication for SSH. This prevents unauthorized reboots even if someone steals your credentials.

Frequently Asked Questions

Can I Restart A Linux Server Without Sudo?

No, you need root or sudo privileges to reboot a Linux server. Regular users don’t have permission to shut down or restart the system.

What Is The Difference Between Reboot And Shutdown -R?

Both commands achieve the same result. shutdown -r offers more options like scheduling and sending messages to users. reboot is simpler and faster.

How Long Does It Take For A Linux Server To Restart?

Most servers restart within 30 to 90 seconds. The time depends on hardware, number of services, and filesystem checks. Large databases or storage arrays can take longer.

Will My SSH Session Reconnect Automatically After Reboot?

No, your SSH session will disconnect and you’ll need to reconnect manually. Some terminal emulators have auto-reconnect features, but they’re not reliable for reboots.

What Should I Do If The Server Doesn’t Come Back After Reboot?

First, check network connectivity with ping. Then use out-of-band management or console access to diagnose the issue. Contact your hosting provider if needed.

Conclusion

Knowing how to restart Linux server from SSH is a fundamental skill for any system administrator. The process is straightforward with commands like sudo reboot or sudo shutdown -r now, but understanding the nuances ensures a smooth experience.

Always prepare before rebooting: save your work, notify users, and have a backup plan. If something goes wrong, use console access or contact support. With practice, remote reboots become second nature.

Now you have the knowledge to handle reboots confidently. Try the methods on a test server first to build familiarity. Your production servers will thank you for the careful approach.