HomeSystemsLinuxConnect to an Ubuntu server as a root using WinSCP

Connect to an Ubuntu server as a root using WinSCP

Using WinSCP is one of the most popular ways to transfer files to a remote Linux server. In this post, I will explain how to connect to an Ubuntu server as a root using WinSCP. First, it is important to note that the root user is not directly accessible with a login operation in Ubuntu and other Linux distributions. Using an unprivileged user as an intermediate login is the first step.

Background

Windows customers can download WinSCP for free and use it as an SFTP client, FTP client, WebDAV client, S3 client, or SCP client. Its primary function is to transfer files between local and remote computers. Additionally, WinSCP supports scripting and basic file management.

If you are using WinSCP to access the root folder, create a new folder (directory), or simply transfer files, you might see one of the following errors if you don’t access it using the root account. 

WinSCP error accessing root folder
WinSCP error creating a new folder or directory

This error happens due to the current user doesn’t have the root rights and permissions will be denied. 

Keep in mind, that for accounts such as root, the direct login is typically disabled by default for security reasons. So when enabling it, have security in mind. And also, you can’t change to a root account in WinSCP when you are already logged into a session, as you can do in the Linux shell using su.

Note: This solution also works for AWS EC2 instances.

Connect to an Ubuntu server as a root using WinSCP

Before continuing, we need to make sure about some obvious things in our Ubuntu server:

  • You have installed the SSH server.
  • You have created a root account.

Option 1

This is the most common option that you’ll see around…

@Your Ubuntu Server

  • Log into your Ubuntu server, and using the terminal (Shell), become root via su or sudo.
  • Run the command visudo to update the /etc/sudoers.tmp file. Then, configure this file to allow other users to become root without a password. Add the following line:
user ALL = (ALL) NOPASSWD: ALL
  • Replace “user” with the user you want to grant access to the root account. Your regular unprivileged username.
Ubuntu - user ALL = (ALL) NOPASSWD: ALL

@Local Machine WinSCP

  • In Win SCP, open a new session. Change the File Protocol option from SFTP (default) to SCP. Input your server credentials, host name, user name, and password. Then hit Advanced…
WinSCP File Protocol SCP
  • In advanced. Go to Environment / SCP/Shell. Under Shell, type:

 sudo su -

  • Leave the rest as default. Click OK.
WinSCP sudo su -
  • On the main login window, click Login.  
  • You should be able to access the root folder now. Or copy and create directories.
WinSCP access to root folder

Option 2

With option 1, you might get another error:

Error skipping startup message. Your shell is probably incompatible with the application (BASH is recommended)

Your shell is probably incompatible with the application (BASH is recommended)

This could be your case, or you just can’t manage to get option 1 to provide root access to your server. In any case, try this option 2. 

@Your Ubuntu Serve

  • Run the command visudo again. This time, add the following line at the end of the file:
ALL=NOPASSWD: /usr/lib/openssh/sftp-server
  • Replace “user” with the user you want to grant access to the root account. Your regular unprivileged username.
Ubuntu ALL=NOPASSWD usrlibopensshsftp-server -

@Local Machine WinSCP

  • In WinSCP, open a new session. In File Protocol, leave SFTP as default. Input your server credentials, host name, user name, and password. Click Advanced…
Connect to an Ubuntu server as a root using WinSCP
  • In advanced. Go to Environment / SFTP. Under Shell, type: 

sudo /usr/lib/openssh/sftp-server

  • Leave the rest as default. Click OK.
WinSCP sftp-server
  • On the main login window, click Login.  
  • This time, you might not able to log in automatically, but after inputting the root account password, you’d be good to go. 
WinSCP Enter root password
  • Now, you should be able to access the root folder. Or copy and create directories.

There are many workarounds to connect to an Ubuntu server as a root, using WinSCP. Here I am sharing two general options based on my experience, but consider that these configurations can vary depending on your scenario, Linux version, and more options.

Note: Take a look at a similar issue using VMware and WinSCP. Unable to Access the VCSA 6.7 via WinSCP

Reference:

WinSCP

Juan Mulford
Juan Mulford
Hey there! I've been in the IT game for over fifteen years now. After hanging out in Taiwan for a decade, I am now in the US. Through this blog, I'm sharing my journey as I play with and roll out cutting-edge tech in the always-changing world of IT.

1 COMMENT

  1. Potentially dumb question regarding #2, if I put a user (for example testuser ALL=NOPASSWD: /usr/lib/openssh/sftp-server) can I still log in with that account normally via SSH and do TTY password sudo with the testuser, or is this account now locked down to only SFTP?

Leave a Reply

- Advertisement -

Popular Articles

mulcas.com-Raspberry-Pi

Raspberry Pi OS in a Virtual Machine with VMware

4
Although the Raspberry Pi OS is designed and optimized for the Raspberry Pi module, it is possible to test and use it without its hardware, with VMware. This solution can be useful if you are a developer (or just a curious guy) and don't have a Raspberry Pi module with you
Unable to delete inaccessible datastore

Unable to delete an "inaccessible" datastore

7
I was switching my storage array, so I migrated the VMs from that old datastore/storage to a new datastore/storage. The old datastore was shared by 3 ESXi hosts, no cluster. After migrating the VMs and unmount/delete the datastore, it was still presented in two of the ESXi hosts and was marked as inaccessible.
This is not a valid source path / URL

This is not a valid source path / URL - SourceTree and Gitlab

1
I have been working on a project with a friend who set up a repository in Gitlab but even though I was able to view all projects on it, I couldn’t really join the repository. I was using SourceTree and Gitlab.
mulcas.com-VMware-OVF-Tool

How to export a Virtual Machine using the VMware OVF Tool

9
The VMware OVF Tool is implemented by VMware for easily importing and exporting virtual machines in Open Virtualization Format (OVF) standard format. Here, I want to show you how to download and install it, and then how to use it from a Windows machine.
Couldn't load private key - Putty key format too new - mulcas.com

Couldn't load private key - Putty key format too new

5
couldn't load private key - Putty key format too new.” This issue happens when you use PuTTygen to generate or convert to a ppk key. Here is how to fix it. 
- Advertisement -

Recent Comments