Score:0

Remove delete command from SFTP/WinSCP

kh flag

Is there any way from which we can restrict any particular user to delete files/folder having full permissions from WinSCP.

Thanks in advance.

Nate T avatar
it flag
full permissions in reference to the user or the folder?
Neha avatar
kh flag
@Nate T user is having full permission on that directory....our requirement is that user will not be able to delete file from that folder from winscp.....on linux server we have set acl for rm command nad its working fine.......but user is able to delete file from winscp....so we want to restrict delete command from winscp...
Nate T avatar
it flag
Do you need to keep Port 22 open? Does this user need to access via SSH for any other reasons, or are other users accessing via SSH?
Nate T avatar
it flag
Also, do you have physical access to the client that you are trying to restrict (is it local or remote)? I think I can answer, but without more detail I can't be sure. Please provide these details, and if I need to update the answer I will do so.
muru avatar
us flag
What ACL did you use, exactly?
cn flag
What do you mean by "delete"? Actually removing a file or also prevent EMPTYING a file (that is essentially also deleting though it is the content)
cn flag
A method: create a directory watcher (there is for instance a python module for this) on the directories you want this. That allows you to disable deleting and also allows you to catch someone removing lines from a file.
hr flag
*"on linux server we have set acl for rm command"* you would probably have better luck setting an appropriate ACL on the directory whose files you want to protect - restrictions on commands are often easily circumvented (ex. the user can't run `rm`, but can run `find -delete`)
Neha avatar
kh flag
@Nate T Do you need to keep Port 22 open? Does this user need to access via SSH for any other reasons, or are other users accessing via SSH?----------yes we need to keep Port 22 open .yes user need to access by SSH for coping files from remote server to local machine and vice versa....yes other users are also accessing via SSH
Neha avatar
kh flag
@Nate T Also, do you have physical access to the client that you are trying to restrict (is it local or remote)? I think I can answer, but without more detail I can't be sure. Please provide these details, and if I need to update the answer I will do so.--------------its remote
Nate T avatar
it flag
This same user who needs restricted also needs ssh read access, or other user(s) need it? (or both?)
Nate T avatar
it flag
Updated my answer. Hopefully this will fare better for you.
Neha avatar
kh flag
@Nate This same user who needs restricted also needs ssh read access, or other user(s) need it? (or both?) – yes, this is the same user that we need to restrict delete operation from putty and from winscp
Neha avatar
kh flag
@Nate T our requirement is that user should not be able to perform delete operation on any of the files/directories from winscp or from putty (for putty we have restricted from acl).....even he/she has full rights on files/directories............
Neha avatar
kh flag
@MartinPrikryl There's nothing like "restriction for putty". PuTTY is just an SSH terminal. It would be nice, if you tell us what did you do exactly.----we have set acl...from this command "/bin/setfacl -m u:john:--- /bin/rm"
tr flag
But `/bin/rm` is by far not the only way to delete a file! As @steeldriver already commented, there's `find -delete`. You can also use some file manager, like Midnight commander. You can use Python, Perl, PHP. And many others. You can *overwrite* a file. You can *move* the file to `/tmp`. + And again, edit your question.
Score:4
tr flag

Remove the write permissions from files and folders server-side.

Alternatively you can restrict the "delete" operation on the SFTP server. See Restrict SFTP user to run only limited set of commands/action in Linux. And make sure the user has an SFTP access only.

Score:2
it flag

I am fairly certain that this can't be done in the way you are hoping (via settings on the winSCP client.) This forum shows evidence of another server administrator with a similar issue. Upon asking, the winSCP site administrator informs him that this is not possible in winSCP, and tells him to focus on the server side.

As the posts suggest, in order to deny this user access, you will need to use server side settings.

One change that is extremely efficient for stopping remote clients from accessing your server (weather via openssh, winscp, or any other SSH client) is to simply close off Port 22. This is the default port for SSH traffic.

EDIT: Still not sure you have given all the relevant info. Going on the info that you have provided so far, if port 22 needs to remain open, you may need to get creative. That said, I am sure a more straight-forward solution could be given if I / we had more context.

Regardless of the method you use to restrict the user's access, you will first need to remove user's sudo privelege. remove with:

gpasswd --delete pbwriters USER

I believe your goal can be achieved server-side by using the chown and chmod commands. You are going to want to set the g= and o= options in after changing the group to which the file belongs. This line should do the trick:

# Replace DIR w/ outermost folder's name
sudo groupadd pbwriters && sudo chown -R :pbwriters DIR && sudo chmod -R 774 DIR

Now, if parentdirectory in the above command is changed to the name of the outermost directory that you want to restrict, then everything inside of that file will only be writable by those in pbwriters group. To give someone write access, you just need to add them to pbwriters group:

# Just as before, replace USER with name of user
sudo usermod -a -G pbwriters USER
Nate T avatar
it flag
As an afterthought, you can also set their $SHELL to [rbash](https://www.networkworld.com/article/2875972/clamping-down-on-users-with-rbash.html). Along with chroot, this is an invaluable tool for network admins. This would at least limit the files they could access.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.