[Midnightbsd-cvs] src [11424] trunk/usr.bin/ssh-copy-id: add ssh-copy-id

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Fri Jul 6 22:41:50 EDT 2018


Revision: 11424
          http://svnweb.midnightbsd.org/src/?rev=11424
Author:   laffer1
Date:     2018-07-06 22:41:50 -0400 (Fri, 06 Jul 2018)
Log Message:
-----------
add ssh-copy-id

Added Paths:
-----------
    trunk/usr.bin/ssh-copy-id/
    trunk/usr.bin/ssh-copy-id/Makefile
    trunk/usr.bin/ssh-copy-id/ssh-copy-id.1
    trunk/usr.bin/ssh-copy-id/ssh-copy-id.sh

Added: trunk/usr.bin/ssh-copy-id/Makefile
===================================================================
--- trunk/usr.bin/ssh-copy-id/Makefile	                        (rev 0)
+++ trunk/usr.bin/ssh-copy-id/Makefile	2018-07-07 02:41:50 UTC (rev 11424)
@@ -0,0 +1,7 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/ssh-copy-id/Makefile 241881 2012-10-22 12:05:14Z eadler $
+
+SCRIPTS= ssh-copy-id.sh
+MAN=	ssh-copy-id.1
+
+.include <bsd.prog.mk>


Property changes on: trunk/usr.bin/ssh-copy-id/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.bin/ssh-copy-id/ssh-copy-id.1
===================================================================
--- trunk/usr.bin/ssh-copy-id/ssh-copy-id.1	                        (rev 0)
+++ trunk/usr.bin/ssh-copy-id/ssh-copy-id.1	2018-07-07 02:41:50 UTC (rev 11424)
@@ -0,0 +1,91 @@
+.\" $MidnightBSD$
+.\"-
+.\" Copyright (c) 2012 Eitan Adler
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD: stable/10/usr.bin/ssh-copy-id/ssh-copy-id.1 262922 2014-03-08 03:54:49Z eadler $
+.\"
+.Dd Feburary 28, 2014
+.Dt SSH-COPY-ID 1
+.Os
+.Sh NAME
+.Nm ssh-copy-id
+.Nd copy public keys to a remote host
+.Sh SYNOPSIS
+.Nm
+.Op Fl lv
+.Op Fl i Ar keyfile
+.Op Fl o Ar option
+.Op Fl p Ar port
+.Oo Ar user Ns @ Oc Ns Ar hostname
+.Sh DESCRIPTION
+The
+.Nm
+utility copies public keys to a remote host's
+.Pa ~/.ssh/authorized_keys
+file (creating the file and directory, if required).
+.Pp
+The following options are available:
+.Bl -tag -width indent
+.It Fl i Ar file
+Copy the public key contained in
+.Ar file .
+This option can be specified multiple times and can be combined with
+the
+.Fl l
+option.
+If a private key is specified and a public key is found then the public key
+will be used.
+.It Fl l
+Copy the keys currently held by
+.Xr ssh-agent 1 .
+This is the default if the
+.Fl i
+option was not specified.
+.It Fl o Ar ssh-option
+Pass this option directly to
+.Xr ssh 1 .
+This option can be specified multiple times.
+.It Fl p Ar port
+Connect to the specified port on the remote host instead of the
+default.
+.It Fl v
+Pass -v to
+.Xr ssh 1 .
+.El
+.Pp
+The remaining arguments are a list of remote hosts to connect to,
+each one optionally qualified by a user name.
+.Sh EXIT STATUS
+.Ex -std
+.Sh EXAMPLES
+To send a specific key to multiple hosts:
+.Dl $ ssh-copy-id -i /path/to/keyfile.pub user at host1 user at host2 user at host3
+.Sh HISTORY
+The
+.Nm
+utility was written by
+.An Eitan Adler Aq eadler at FreeBSD.org
+as a drop-in replacement for an existing utility included with
+OpenSSH.


Property changes on: trunk/usr.bin/ssh-copy-id/ssh-copy-id.1
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.bin/ssh-copy-id/ssh-copy-id.sh
===================================================================
--- trunk/usr.bin/ssh-copy-id/ssh-copy-id.sh	                        (rev 0)
+++ trunk/usr.bin/ssh-copy-id/ssh-copy-id.sh	2018-07-07 02:41:50 UTC (rev 11424)
@@ -0,0 +1,118 @@
+#!/bin/sh
+#-
+# Copyright (c) 2012 Eitan Adler
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer
+#    in this position and unchanged.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD: stable/10/usr.bin/ssh-copy-id/ssh-copy-id.sh 284197 2015-06-10 01:17:14Z eadler $
+# $MidnightBSD$
+
+usage() {
+	echo "usage: ssh-copy-id [-lv] [-i keyfile] [-o option] [-p port] [user@]hostname" >&2
+	exit 1
+}
+
+sendkey() {
+	local h="$1"
+	local k="$2"
+	printf "%s\n" "$k" | ssh $port -S none $options "$user$h" /bin/sh -c \'' \
+		set -e; \
+		umask 077; \
+		keyfile=$HOME/.ssh/authorized_keys ; \
+		mkdir -p -- "$HOME/.ssh/" ; \
+		while read alg key comment ; do \
+			[ -n "$key" ] || continue; \
+			if ! grep -sqwF "$key" "$keyfile"; then \
+				printf "$alg $key $comment\n" >> "$keyfile" ; \
+			fi ; \
+		done ; \
+		if [ -x /sbin/restorecon ]; then \
+			/sbin/restorecon -F "$HOME/.ssh/" "$keyfile" >/dev/null 2>&1 || true ; \
+		fi \
+	'\' 
+}
+
+agentKeys() {
+	keys="$(ssh-add -L | grep -v 'The agent has no identities.')$nl$keys"
+}
+
+keys=""
+host=""
+hasarg=""
+user=""
+port=""
+nl="
+"
+options=""
+
+IFS=$nl
+
+while getopts 'i:lo:p:v' arg; do
+	case $arg in
+	i)	
+		hasarg="x"
+		if [ -r "${OPTARG}.pub" ]; then
+			keys="$(cat -- "${OPTARG}.pub")$nl$keys"
+		elif [ -r "$OPTARG" ]; then
+			keys="$(cat -- "$OPTARG")$nl$keys"
+		else
+			echo "File $OPTARG not found" >&2
+			exit 1
+		fi
+		;;
+	l)	
+		hasarg="x"
+		agentKeys
+		;;
+	p)	
+		port=-p$nl$OPTARG
+		;;
+	o)	
+		options=$options$nl-o$nl$OPTARG
+		;;
+	v)
+		options="$options$nl-v"
+		;;
+	*)	
+		usage
+		;;
+	esac
+done >&2
+
+shift $((OPTIND-1))
+
+if [ -z "$hasarg" ]; then
+	agentKeys
+fi
+if [ -z "$keys" ] || [ "$keys" = "$nl" ]; then
+	echo "no keys found" >&2
+	exit 1
+fi
+if [ "$#" -eq 0 ]; then
+	usage
+fi
+
+for host in "$@"; do
+	sendkey "$host" "$keys"
+done


Property changes on: trunk/usr.bin/ssh-copy-id/ssh-copy-id.sh
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property


More information about the Midnightbsd-cvs mailing list