SSH – Use SFTP with Sudo for Root Access and SSH Key Authentication

sftpssh

I want to be able to use SFTP to edit files that require root permissions.

I'm using SSH Key based authentication – rsa key on smart card.

If the system requires sudo to perform root level commands, How do I get around this?

Can I create a way of bypassing sudo for SFTP only?

Is there a way to keep sudo & key authentication.

I'm using windows to connect to Ubuntu. I need this to work with Mac connecting to Ubuntu as well.

I understand how to do SSH Tunneling to admin the system services. Currently, I use root user login directly, but password login is disabled. I didn't understand how to use sudo and SFTP at same time. It seems to be a best practice to require login as a non-root user and then require use of sudo since the logs will record who was given escalated privileges for each command.

Should I concern myself with this when using Key based authentication or is this a trivial difference in security/logging? It seems like Key based authentication records user's serial number in the logs, and you can have multiple keys for the root user to identify each user. This seems to be the same effect as using sudo to me. Am I wrong?

Best Answer

SFTP is a command access to file operations, with the restrictions from the account you use. You must use ssh for make more administrative operations, making impossible use sudo and SFTP at same time. If you need access to the entire disk without restriction using SFTP, do it using the root account. Anyway you can make a login with root on sftp and ssh at same time, of course, using two different sessions.

The security keys improve the security and make more easy the logging, not requiring keyboard input. Only helps to make login, you can had several passwords for every account user and had the same effect.

EDIT: I forgot: you can create another account with the same effect than root if you assign the user id to 0, but not had any sense, being dangerous in the same way. Could give some obfuscation if somebody try to login like root, but apart of that, not had much sense.

Related Question