На удаленный сервер нужно послать команду, выполняемую от root по SSH. Авторизация на удаленном сервере происходит только по ключам.
На обоих машинах:
Код: Выделить всё
OpenSSH_4.5p1 FreeBSD-20061110, OpenSSL 0.9.8e 23 Feb 2007
Код: Выделить всё
Port 22
Protocol 2
ListenAddress 0.0.0.0
LogLevel DEBUG3
PermitRootLogin forced-commands-only
MaxAuthTries 0
UseDNS no
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
PermitEmptyPasswords no
UsePAM no
AllowUsers alex root
Subsystem sftp /usr/libexec/sftp-server
Код: Выделить всё
from="y.y.y.y",command="/sbin/pfctl -q -t NETAMS_INET -T add < /root/KP_ANOTHER_HOST; pfctl -q -k < /root/KP_ANOTHER_HOST",command="scp -v -t /root/KP_ANOTHER_HOST" ssh-rsa AAA...0nOlds2rbx3Q== root@bladecreeper
Сам скрипт, посылающий команду на сервер - это стандартная команда NETAMS'a (ввиду параметра PermitRootLogin forced-commands-only, в authorized_keys требуется жестко прописывать команды, поэтому пришлось немного извратиться)
Код: Выделить всё
#!/bin/sh
KP_SUBNET="172.17.4."
PRIVATE_KEY="/root/.ssh/rsa.key"
KP_GW="x.x.x.x"
FILE="KP_ANOTHER_HOST"
case $1 in
DENY)
if [ `echo $3 | grep $KP_SUBNET` ]
then
echo $3 > /tmp/$FILE
scp -i $PRIVATE_KEY /tmp/$FILE root@$KP_GW:/root/$FILE
ssh -l root -i $PRIVATE_KEY $KP_GW '/sbin/pfctl -q -t NETAMS_INET -T add < /root/KP_ANOTHER_HOST; pfctl -q -k < /root/KP_ANOTHER_HOST'
else
pfctl -q -t NETAMS_INET -T add $3
pfctl -q -k $3
fi
;;
ALLOW)
if [ `echo $3 | grep $KP_SUBNET` ]
then
echo $3 > /tmp/$FILE
scp -i $PRIVATE_KEY /tmp/$FILE root@$KP_GW:/root/$FILE
ssh -l root -i $PRIVATE_KEY $KP_GW '/sbin/pfctl -q -t NETAMS_INET -T delete < /root/KP_ANOTHER_HOST; pfctl -q -k < /root/KP_ANOTHER_HOST '
else
pfctl -q -t NETAMS_INET -T delete $3
pfctl -q -k $3
fi
;;
esac
exit 0
Теперь значит такой лог при коннекте (сразу оговорюсь, с ключами все в порядке, генерились стандартным способом ssh-keygen):
Код: Выделить всё
[8:06 root@darkstar /home/alex]# ./testing.sh DENY 000 172.17.4.52
Sink: C0644 12 KP_ANOTHER_HOST
KP_ANOTHER_HOST 100% 12 0.0KB/s 00:00
OpenSSH_4.5p1 FreeBSD-20061110, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to x.x.x.x [x.x.x.x] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/rsa.key type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.5p1 FreeBSD-20061110
debug1: match: OpenSSH_4.5p1 FreeBSD-20061110 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.5p1 FreeBSD-20061110
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '81.13.39.162' is known and matches the DSA host key.
debug1: Found key in /root/.ssh/known_hosts:15
debug1: ssh_dss_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/rsa.key
debug1: read PEM private key done: type RSA
debug1: Remote: Forced command: /sbin/pfctl -q -t NETAMS_INET -T add < /root/KP_ANOTHER_HOST; pfctl -q -k < /root/KP_ANOTHER_HOST
debug1: Remote: Forced command: scp -v -t /root/KP_ANOTHER_HOST
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending command: /sbin/pfctl -q -t NETAMS_INET -T add < /root/KP_ANOTHER_HOST; pfctl -q -k < /root/KP_ANOTHER_HOST
scp: protocol error: unexpected <newline>
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 12.6 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 1
Код: Выделить всё
scp: protocol error: unexpected <newline>
Код: Выделить всё
[8:08 root@bladecreeper /home/alex]# ssh -v localhost
OpenSSH_4.5p1 FreeBSD-20061110, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.5p1 FreeBSD-20061110
debug1: match: OpenSSH_4.5p1 FreeBSD-20061110 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.5p1 FreeBSD-20061110
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'localhost' is known and matches the DSA host key.
debug1: Found key in /root/.ssh/known_hosts:2
debug1: ssh_dss_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: read PEM private key done: type RSA
debug1: Remote: Forced command: /sbin/pfctl -q -t NETAMS_INET -T add < /root/KP_ANOTHER_HOST; pfctl -q -k < /root/KP_ANOTHER_HOST
debug1: Remote: Forced command: scp -v -t /root/KP_ANOTHER_HOST
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
scp: protocol error: unexpected <newline>
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Connection to localhost closed.
debug1: Transferred: stdin 0, stdout 0, stderr 33 bytes in 1.0 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 31.4
debug1: Exit status 1
В scp.c есть такая строка:
Код: Выделить всё
if (ch == '\n')
bump("Protocol error: Unexpected newline");
Может кто сталкивался с этим и подскажет мне откуда мои кривые руки растут ?

P.S. Под другим пользователем заходит по ключу нормально. Я конечно понимаю что можно заюзать sudo, но хотелось бы понять в чем тут проблема.