Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
etersoft-admin-essentials
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
etersoft-admin-essentials
Commits
2587c58f
Commit
2587c58f
authored
Apr 07, 2017
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add set_eterkey.sh (will need union with add_eterkey.sh)
parent
1564d839
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
0 deletions
+81
-0
set_eterkey.sh
rooter/set_eterkey.sh
+81
-0
No files found.
rooter/set_eterkey.sh
0 → 100755
View file @
2587c58f
#!/bin/sh
# Args: username host VEID keyuser
docmd
()
{
echo
"
\$
$@
"
"
$@
"
}
fatal
()
{
echo
-e
"Error:
$@
"
>
&2
exit
1
}
USERNAME
=
$1
HOST
=
$2
VEID
=
$3
KEYUSER
=
$4
Help
=
"Usage:
$0
USERNAME HOST VEID [KEYUSER]
\n
HOST - from yours ssh alias
\n
VEID - container ID or 0 for host system
\n
KEYUSER - which key"
if
[
"
$USERNAME
"
=
"-h"
]
;
then
echo
-e
"
$Help
"
exit
fi
if
[
-z
"
$USERNAME
"
]
||
[
-z
"
$HOST
"
]
||
[
-z
"
$VEID
"
]
;
then
fatal
"
$Help
"
fi
# local user by default
[
-n
"
$KEYUSER
"
]
||
KEYUSER
=
"
$USER
"
USERKEY
=
$(
ssh rooter@server pubkey
$KEYUSER
)
[
-n
"
$USERKEY
"
]
||
fatal
"Can't get ssh key"
ssh
$HOST
echo
||
fatal
"Host
$HOST
is not sshed"
SUDO
=
[
"
$UID
"
=
0
]
||
SUDO
=
"sudo"
HOSTSUDO
=
$SUDO
SSHOPT
=
""
# FIXME: почему-то в cat не раскрывается тильда!
#ADDKEYCMD="useradd $USERNAME ; su - $USERNAME -c 'mkdir -p ~/.ssh ; chmod 700 ~/.ssh ; touch ~/.ssh/authorized_keys ; chmod 600 ~/.ssh/authorized_keys' ; cat >> /home/$USERNAME/.ssh/authorized_keys"
HSSH
=
/home/
$USERNAME
/.ssh
# TODO: исправить повторное добавление ключей
add_key_cmd
()
{
#echo "$SUDO useradd $USERNAME ; $SUDO su - $USERNAME -c 'mkdir -p $HSSH ; chmod 700 $HSSH ; touch $HSSH/authorized_keys ; chmod 600 $HSSH/authorized_keys ; cat >> $HSSH/authorized_keys'"
echo
"
$SUDO
su -
$USERNAME
-c 'mkdir -p
$HSSH
; chmod 700
$HSSH
; touch
$HSSH
/authorized_keys ; chmod 600
$HSSH
/authorized_keys ; cat >>
$HSSH
/authorized_keys'"
}
# copy key in host system
if
[
-z
"
$VEID
"
]
||
[
"
$VEID
"
=
0
]
;
then
echo
"Copy key for
$KEYUSER
to host
$HOST
"
# FIXME: не работает на CentOS
echo
"
$USERKEY
"
| docmd ssh
$SSHOPT
$HOST
"
$(
add_key_cmd
)
"
ssh
$SSHOPT
$HOST
$HOSTSUDO
ls
/home/
$USERNAME
/.ssh
-l
#ssh -i $USERKEY $USERNAME@$HOST ls ~/.ssh -l
# TODO (.gitconfig)
# git config --global user.email "you@example.com"
# git config --global user.name "Your Name"
exit
fi
# TODO: move?
# show container list
if
[
"
$VEID
"
=
"-l"
]
;
then
docmd ssh
$SSHOPT
$HOST
$HOSTSUDO
vzlist
exit
fi
# copy key in VEID container at host system
echo
"Copy
$KEYUSER
key to
$USERNAME
on
$HOST
, VEID=
$VEID
"
SUDO
=
echo
"
$USERKEY
"
| ssh
$SSHOPT
$HOST
"
$HOSTSUDO
vzctl exec
$VEID
\"
$(
add_key_cmd
)
\"
"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment