Difference between pages "Git local overlay" and "SFTP Only Access"

(Difference between pages)
(Created page with "Here is How To: Work with local overlay synchronized with your git repository. == Setup git local overlay == === Create local overlay === Create the necessary directory struct...")
 
 
Line 1: Line 1:
Here is How To: Work with local overlay synchronized with your git repository.
+
= Context =
  
== Setup git local overlay ==
+
In some cases, it can be useful to set up an access on your Funtoo box such as a user:
 +
* does not see the whole contents of the machine but, instead, remains "jailed" in a home directory
 +
* is able to transfer files back and forth on the box via SFTP
 +
* does not have access to a shell
  
=== Create local overlay ===
+
Such a SFTP only access is easy to setup:
  
Create the necessary directory structure
+
# Assign a group (e.g. ''sftponly'') to users that must be restricted to a SFTP-only account
<pre>
+
# Change a bit the configuration of OpenSSH so that users belonging to your sftp-only group are given a chrooted access
# mkdir -p /usr/local/portage/profiles
+
# Make OpenSSH ignore any other command than running sftp-server on the server side for users belonging to your sftp-only group (this is where the trick lies !)
# echo "$HOSTNAME" >> /usr/local/portage/profiles/repo_name
+
</pre>
+
  
This enables access to /usr/local/portage
+
= Quick start =
for users in the portage group
+
<pre>
+
# chown root:portage /usr/local/portage
+
</pre>
+
  
Assign the portage group as default for newly created files in
+
First, a dedicated group must be created. For the sake of the example we use sftponly here, use whatever name fits your preferences:
/usr/local/portage
+
<pre>
+
# chmod g+s /usr/local/portage
+
</pre>
+
  
Enable users in the portage group to write to
 
/usr/local/portage
 
 
<pre>
 
<pre>
# chmod 775 /usr/local/portage
+
# groupadd sftponly
 
</pre>
 
</pre>
  
Edit make.conf
+
Next in the configuration of OpenSSH (located in '''/etc/sshd/sshd_config''') locate:
<pre>
+
# echo "PORTDIR_OVERLAY=/usr/local/portage" >> /etc/make.conf
+
</pre>
+
  
Logout as root
 
 
<pre>
 
<pre>
# exit
+
Subsystem      sftp    /usr/lib64/misc/sftp-server
 
</pre>
 
</pre>
  
Create the relevant directory structure
+
and change it for:
(I use the game rain-slick as example)
+
<pre>
+
$ mkdir -p /usr/local/portage/games-rpg/rain-slick
+
</pre>
+
  
Copy the ebuild to your overlay
 
 
<pre>
 
<pre>
$ cp rain-slick-1.5.ebuild /usr/local/portage/games-rpg/rain-slick
+
Subsystem      sftp    internal-sftp
 
</pre>
 
</pre>
  
Issue the following commands to install rain-slick from your overlay
+
Now the $100 question: ''"how can OpenSSH can be told to restrict a user access to a simple sftp session?"'' Simple! Assuming that ''sftponly'' is the group you use for for your restricted users, just add to the file '''/etc/sshd/sshd_config''' the following statement:
 +
 
 
<pre>
 
<pre>
$ cd /usr/local/portage/games-rpg/rain-slick
+
# Restricted users, no TCP connexions bouncing, no X tunneling.
$ ebuild rain-slick-1.5.ebuild digest
+
Match group sftponly
$ su
+
        ChrootDirectory /home/%u
# emerge -a rain-slick
+
        X11Forwarding no
 +
        AllowTcpForwarding no
 +
        ForceCommand internal-sftp
 
</pre>
 
</pre>
  
=== Synchronize with git repository ===
+
To understand how it works, you must be aware that, when you open an SSH session, the SSHD process launch a process on the server side which could be:
 +
* a shell => ssh login@host
 +
* a kind of dedicated ftp daemon (sftp-server) => sftp user@host
  
If you are not related with git and ssh you can check [http://help.github.com/ this] GitHub manual.
+
TBC
If you have not git repository with local overlay yet you can assign it alike :
+
<pre>
+
$ cd /usr/local/portage/
+
$ git add /usr/local/portage/profiles/repo_name
+
$ git commit -m 'git init'
+
$ git remote add origin git@github.com:YourGitHubAccount/YourGitHubRepository.git
+
$ git push -u origin master
+
</pre>
+
  
If you already have git overlay repository or want to use some you can assign it alike :
+
[[Category:HOWTO]]
<pre>
+
$ cd /usr/local/portage/
+
$ git init
+
$ git remote add origin git@github.com:YourGitHubAccount/YourGitHubRepository.git
+
$ git fetch
+
$ git branch master origin/master
+
$ git checkout master
+
</pre>
+

Revision as of 16:50, 30 August 2011

Context

In some cases, it can be useful to set up an access on your Funtoo box such as a user:

  • does not see the whole contents of the machine but, instead, remains "jailed" in a home directory
  • is able to transfer files back and forth on the box via SFTP
  • does not have access to a shell

Such a SFTP only access is easy to setup:

  1. Assign a group (e.g. sftponly) to users that must be restricted to a SFTP-only account
  2. Change a bit the configuration of OpenSSH so that users belonging to your sftp-only group are given a chrooted access
  3. Make OpenSSH ignore any other command than running sftp-server on the server side for users belonging to your sftp-only group (this is where the trick lies !)

Quick start

First, a dedicated group must be created. For the sake of the example we use sftponly here, use whatever name fits your preferences:

# groupadd sftponly

Next in the configuration of OpenSSH (located in /etc/sshd/sshd_config) locate:

Subsystem      sftp    /usr/lib64/misc/sftp-server

and change it for:

Subsystem      sftp    internal-sftp

Now the $100 question: "how can OpenSSH can be told to restrict a user access to a simple sftp session?" Simple! Assuming that sftponly is the group you use for for your restricted users, just add to the file /etc/sshd/sshd_config the following statement:

# Restricted users, no TCP connexions bouncing, no X tunneling.
Match group sftponly
        ChrootDirectory /home/%u
        X11Forwarding no
        AllowTcpForwarding no
        ForceCommand internal-sftp

To understand how it works, you must be aware that, when you open an SSH session, the SSHD process launch a process on the server side which could be:

  • a shell => ssh login@host
  • a kind of dedicated ftp daemon (sftp-server) => sftp user@host

TBC