4
# lxc: linux Container library
7
# Daniel Lezcano <daniel.lezcano@free.fr>
9
# This library is free software; you can redistribute it and/or
10
# modify it under the terms of the GNU Lesser General Public
11
# License as published by the Free Software Foundation; either
12
# version 2.1 of the License, or (at your option) any later version.
14
# This library is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
# Lesser General Public License for more details.
19
# You should have received a copy of the GNU Lesser General Public
20
# License along with this library; if not, write to the Free Software
21
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
$rootfs/var/run/sshd \
29
$rootfs/var/empty/sshd \
30
$rootfs/var/lib/empty/sshd \
55
cat <<EOF > $rootfs/etc/passwd
56
root:x:0:0:root:/root:/bin/bash
57
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
60
cat <<EOF > $rootfs/etc/group
65
ssh-keygen -t rsa -f $rootfs/etc/ssh/ssh_host_rsa_key
66
ssh-keygen -t dsa -f $rootfs/etc/ssh/ssh_host_dsa_key
68
# by default setup root password with no password
69
cat <<EOF > $rootfs/etc/ssh/sshd_config
72
HostKey /etc/ssh/ssh_host_rsa_key
73
HostKey /etc/ssh/ssh_host_dsa_key
74
UsePrivilegeSeparation yes
75
KeyRegenerationInterval 3600
83
PubkeyAuthentication yes
85
RhostsRSAAuthentication no
86
HostbasedAuthentication no
87
PermitEmptyPasswords yes
88
ChallengeResponseAuthentication no
99
cat <<EOF >> $path/config
103
lxc.mount.entry=/dev $rootfs/dev none ro,bind 0 0
104
lxc.mount.entry=/lib $rootfs/lib none ro,bind 0 0
105
lxc.mount.entry=/bin $rootfs/bin none ro,bind 0 0
106
lxc.mount.entry=/usr /$rootfs/usr none ro,bind 0 0
107
lxc.mount.entry=/sbin $rootfs/sbin none ro,bind 0 0
108
lxc.mount.entry=tmpfs $rootfs/var/run/sshd tmpfs mode=0644 0 0
109
lxc.mount.entry=@LXCTEMPLATEDIR@/lxc-sshd $rootfs/sbin/init none bind 0 0
112
if [ "$(uname -m)" = "x86_64" ]; then
113
cat <<EOF >> $path/config
114
lxc.mount.entry=/lib64 $rootfs/lib64 none ro,bind 0 0
122
$1 -h|--help -p|--path=<path>
127
options=$(getopt -o hp:n: -l help,path:,name: -- "$@")
128
if [ $? -ne 0 ]; then
132
eval set -- "$options"
137
-h|--help) usage $0 && exit 0;;
138
-p|--path) path=$2; shift 2;;
139
-n|--name) name=$2; shift 2;;
140
--) shift 1; break ;;
145
if [ "$(id -u)" != "0" ]; then
146
echo "This script should be run as 'root'"
150
if [ $0 == "/sbin/init" ]; then
152
type @LXCINITDIR@/lxc-init
153
if [ $? -ne 0 ]; then
154
echo "'lxc-init is not accessible on the system"
159
if [ $? -ne 0 ]; then
160
echo "'sshd' is not accessible on the system "
164
exec @LXCINITDIR@/lxc-init -- /usr/sbin/sshd
168
if [ -z "$path" ]; then
169
echo "'path' parameter is required"
176
if [ $? -ne 0 ]; then
177
echo "failed to install sshd's rootfs"
181
configure_sshd $rootfs
182
if [ $? -ne 0 ]; then
183
echo "failed to configure sshd template"
187
copy_configuration $path $rootfs $name
188
if [ $? -ne 0 ]; then
189
echo "failed to write configuration file"