This guide shows you how to log in to your VPS via SSH and gain root access. You'll learn how to connect with your username and password, set a secure root password, and then elevate your privileges to the root level for administrative tasks.
How to do it
-
Step 1: Log in with your VPS credentials
To begin, you'll need to connect to your VPS using SSH. Open a terminal window on your local machine and use the following command, replacing
usernamewith your actual username andyour-vps-ipwith your VPS's IP address:ssh username@your-vps-ipIf this is your first time connecting to the server, you may see a warning about the authenticity of the host. Type
yesand press Enter to continue.You will then be prompted to enter your password. Make sure to type it carefully as no characters will appear on the screen for security reasons. Press Enter after typing your password.
-
Step 2: Set a root password
Once logged in, you should set a strong password for the root user to ensure better security. Run the following command:
sudo passwd rootYou will be prompted to enter your current user's password first as a verification step. Then, you'll need to create and confirm a new root password. Ensure that this password is strong and unique to avoid unauthorized access.
-
Step 3: Switch to root user
After setting the root password, you can switch to the root user by entering:
suYou will be prompted to enter the root password you just created. Once authenticated, your command prompt should change to indicate that you are now logged in as the root user.
Tips:
- Always use strong, unique passwords for both your regular and root accounts.
- Consider using SSH keys instead of passwords for added security. You can generate an SSH key pair on your local machine and add the public key to your VPS's authorized_keys file.
- Be cautious when logged in as the root user, as you have full administrative privileges and any mistakes could affect the entire system.