Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Security
User Name
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.


  Search this Thread
Old 11-27-2008, 09:22 AM   #1
LQ Newbie
Registered: Oct 2005
Location: France
Distribution: Arch
Posts: 23

Rep: Reputation: 0
ssh : allowing only scp and 1 command


I try to configure ssh for allowing only 1 command and scp.

I've changed ~/.ssh/authorized_key like this :
command="/tmp/myscript" ....
Here is /tmp/myscript :

exec 1>&2

echo "$SSH_ORIGINAL_COMMAND" | grep -q '^scp'
if [ $? -eq 0 ] ; then
        echo "scp demandé"
        params="$(echo $SSH_ORIGINAL_COMMAND | cut -d ' ' -f 2-)"
        echo "Execution de scp $params"
        exec scp -v $params
        ls /tmp | wc -l
The scp server runs, but there is no transfert :-/

I tryed to apply this to make my own wrapper, but what i've made doesn't work (i prefer using bash script).

How is it possible to allow only scp and 1 command?
Old 11-27-2008, 11:07 AM   #2
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391

I have half an answer and a suggestion for a different approach.

Half the answer first: There is a program that's called scponly, which disables normal ssh logins and only permits the use of scp (hence scponly). But this only solves half your problem, I would not know how to combine scponly with the '1 specific command' only request.

If you are interested in scponly, feed your favorite search engine. Here are 2 links to get you going:

scponly - wiki
scponly - freshmeat

Maybe you can use a different approach: You could consider creating a specific account that has a script as a 'shell' instead of the standard bash/ksh/... shell. When one logs into that account the script, which could be anything from a single command to a menu with multiple things, is executed and the user is logged out again afterwards.

Hope this gets you going again.
Old 11-28-2008, 03:45 PM   #3
LQ Newbie
Registered: Oct 2005
Location: France
Distribution: Arch
Posts: 23

Original Poster
Rep: Reputation: 0
The script below works to allow scp and other restricted commands :


echo $SSH_ORIGINAL_COMMAND | grep '^scp'
if [ $? -eq 0 ] ; then
   echo "ssh command to execute : ${SSH_ORIGINAL_COMMAND}"
exit 0


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to simulate scp command using ssh? vickylife Linux - Newbie 3 11-18-2008 05:22 AM
How to use EXPECT command to scp or ssh? thefountainhead100 Linux - Software 6 03-28-2008 06:41 PM
Translating windows pscp command to linux scp command help robward Linux - General 2 01-17-2008 06:02 AM
Is Allowing SSH Safe? Optimistic Linux - Security 10 03-21-2005 01:58 PM
Allowing for incoming ssh InsaneBob Linux - Software 11 04-12-2003 01:44 PM > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 05:08 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration