Home > ssh > How to execute a script on sftp connection?

How to execute a script on sftp connection?

September 24Hits:8
Advertisement

I run an ssh server on my machine and I restrict access to certain users to sftp only with internal-sftp & ChrootDirectory. What I need is a way to execute a script before chrooting users. Actually, the goal is to mount an encrypted filesystem on client connection and unmount it on close. Thx in advance.

Answers

If you don't want to hack the openssh code you have to use the external sftp server. If you do it is a simple matter of putting a wrapper around it. For example: in sshd_config

Subsystem       sftp    /usr/local/bin/sftp-server

In /usr/local/bin/sftp-server:

#!/bin/sh
mount_special_fs
chroot /my/secret/stuff /usr/libexec/openssh/sftp-server
umount_special_fs

It might be possible to put a wrapper around sshd and launch the wrapper from inetd but launching sshd from inted is discouraged because it is to slow to start up.

You can also use pam_script, a pam module to execute script from a pam authentication module. You can add it in your pam sshd configuration. URL: http://linux.die.net/man/5/pam_script

Tags:ssh, sftp

Related Articles

  • How to execute a script on sftp connection?September 24

    I run an ssh server on my machine and I restrict access to certain users to sftp only with internal-sftp & ChrootDirectory. What I need is a way to execute a script before chrooting users. Actually, the goal is to mount an encrypted filesystem on cli

  • Executing python script without being connected to serverFebruary 4

    I need to execute python script on remote server (access through puTTY), but I don't have a stable Internet connection, and every time I execute the script I get problems after several minutes due to my Internet getting disconnected. How do I remotel

  • Mac 10.6 Cisco VPN: Can I run scripts/apps on connection?September 4

    I had been using shimo to connect to my vpn and shimo has the ability to execute apps/scripts when the connection happens. I have moved to 10.6 and am now using the built in client. I don't see any way to execute apps/scripts when the built in client

  • How can I remotely log on to a machine, execute a script which sets up an environment, then accept user input?October 1

    I've been trying to figure out a way to do this for a few hours now, and am having no luck. I have a large environment file that I have saved as a ksh script. This script works perfect if I type . ./setEnv.sh However, what I'm trying to do is use eit

  • How to open sftp connection and execute sftp command in the same shell command November 18

    Is there any possibility for opening sftp connection to remote server and execute sftp command in same line from shell. Something like this: sftp [email protected] && put /tmp/test.txt /tmp/ where put is sftp command. My idea is to put file from lo

  • Execute script when [dis]connected to wifi?September 18

    I have two one-liner scripts that write IP address and SSID to files in my Dropbox; I would like my Android phone to sync to Dropbox and read the IP and SSID and do stuff via Tasker if it's on the same network. That said, I am looking for a way to ex

  • Openvpn-server: Execute a script when on a failed connection?April 3

    Good morning, I was wondering if It was possible to setup something to execute a script when someone tried to connect but the TLS check failed (When someone who is not supposed to connected try to┬░ I would like to be able to execute a script to send

  • Server load affection due to excesive sftp connections to sync serverDecember 12

    I am planning to sync around 200 very small files per hour (less than 1KB each file), the source files are on a remote SFTP server and the destination files are on a Windows Server. My fear is the too many connections that I plan to do to the SFTP se

  • How can I execute Ruby scripts via Apache (not necessarily using Rails)?January 27

    I'm trying to get Apache to interpret my Ruby files but I don't understand how to do it. I'm not concerned with Rails right now, only Ruby. What I've found by Googling only confuses me. Any advice? --------------Solutions------------- The most common

  • Execute remote script with local parameter valueJuly 15

    How can I automatize this task? 1) You are at A. 2) You ssh into B. 3) You run a script at B, that needs a parameter known at A. First, I thought perhaps I could send the value when I opened the connection with ssh. Then, probably simpler, between 1)

  • Executing a script from Nagios event handler fails to runOctober 12

    I have Nagios running on a webserver. For this one Nagios service check in particular, if it fails, it will run a script. This script is triggered via Nagios event handlers. Nagios event handler command: define command{ command_name testDisableServer

  • Tool to execute shell scriptNovember 15

    I have a requirement to execute multiple shell scripts on the Linux severs regularly. Is there any tool in windows that connect to a Linux server and execute the given script with given user and shows the output in windows machine. --------------Solu

  • Cron job is running but not executing entire script November 17

    This is a Canonical Question about using cron & crontab. The answer for 'Why is my crontab not working, and how can I troubleshoot it?' can be seen below. This addresses the cron system with the crontab highlighted. --------------Solutions-----------

  • How to execute a script that takes a long time?February 13

    I am executing a script by calling a URL using the wget command. I want to execute this script 3 times a day for 2 hours each time. To do so, I check the difference between the start time and the current time. My problem is that sometimes the script

  • Net::SFTP connection not closingSeptember 10

    I have a Ruby on Rails (Rails 3.2.14 and ruby 1.9.3) application that uploads 2 files to a remote SFTP server. The SFTP code is: require 'net/sftp' Rails.logger.info("Creating SFTP connection") uri = URI.parse('sftp://'+ host) Net::SFTP.start(ur

  • How to execute shell script in remote windows machine March 22

    I am planning to run a bash script on a remote Windows system from my local Linux machine. For this purpose, I will have to log in to Windows machine from the local one and then execute the bash Script. First of all, is this possible? If yes, then ho

  • Locked myself out of Amazon EC2 SSH - This service allows sftp connections only

    Locked myself out of Amazon EC2 SSH - This service allows sftp connections onlyJuly 11

    Doh. Locked myself out of SSH on an Amazon EC2 box after fiddling with ForceCommand internal-sftp in /etc/ssh/sshd_config in order to allow root log-in via SFTP. SFTP still works fine, but PuTTY dies instantly, e.g: The odd thing here is that SFTP st

  • how to retrieve following error when i execute shell scriptJuly 19

    I have one script to log into remote server.But i tried to Execute the script some error occur. Logs: My script: #!/bin/bash S1=$(ssh -t selvam-odc-shell1 "users | wc -w ") S2=$(ssh -t selvam-odc-shell2 "users | wc -w ") S3=$(ssh -t se

  • How to execute a script from trusted shellMarch 31

    I am new to Linux. I have copied the bash program from bin to a thumb drive. I have renamed it to "ebash". Now I connect this thumb drive to other Linux machine. I have mounted this drive and navigated to the directory where I have placed ebash

  • Openvpn script on (re)connect?August 5

    Openvpn can execute a script upon connection using the --up parameter. However this does not seem to work at reconnecting, i.e. when a connection is lost and openvpn automatically reconnects. Is this normal behaviour and is there a way to execute scr

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.734 s.