diff options
Diffstat (limited to 'usr.bin/ssh-copy-id')
-rw-r--r-- | usr.bin/ssh-copy-id/Makefile | 5 | ||||
-rw-r--r-- | usr.bin/ssh-copy-id/Makefile.depend | 10 | ||||
-rw-r--r-- | usr.bin/ssh-copy-id/ssh-copy-id.1 | 87 | ||||
-rwxr-xr-x | usr.bin/ssh-copy-id/ssh-copy-id.sh | 117 |
4 files changed, 219 insertions, 0 deletions
diff --git a/usr.bin/ssh-copy-id/Makefile b/usr.bin/ssh-copy-id/Makefile new file mode 100644 index 000000000000..66a742726d6e --- /dev/null +++ b/usr.bin/ssh-copy-id/Makefile @@ -0,0 +1,5 @@ +SCRIPTS= ssh-copy-id.sh +MAN= ssh-copy-id.1 +PACKAGE= ssh + +.include <bsd.prog.mk> diff --git a/usr.bin/ssh-copy-id/Makefile.depend b/usr.bin/ssh-copy-id/Makefile.depend new file mode 100644 index 000000000000..11aba52f82cf --- /dev/null +++ b/usr.bin/ssh-copy-id/Makefile.depend @@ -0,0 +1,10 @@ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/usr.bin/ssh-copy-id/ssh-copy-id.1 b/usr.bin/ssh-copy-id/ssh-copy-id.1 new file mode 100644 index 000000000000..9909aa6f2d91 --- /dev/null +++ b/usr.bin/ssh-copy-id/ssh-copy-id.1 @@ -0,0 +1,87 @@ +.\"- +.\" Copyright (c) 2012 Eitan Adler +.\" +.\" 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. +.\" +.Dd February 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@host1 user@host2 user@host3 +.Sh HISTORY +The +.Nm +utility was written by +.An Eitan Adler Aq Mt eadler@FreeBSD.org +as a drop-in replacement for an existing utility included with +OpenSSH. diff --git a/usr.bin/ssh-copy-id/ssh-copy-id.sh b/usr.bin/ssh-copy-id/ssh-copy-id.sh new file mode 100755 index 000000000000..e19a9348a597 --- /dev/null +++ b/usr.bin/ssh-copy-id/ssh-copy-id.sh @@ -0,0 +1,117 @@ +#!/bin/sh +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2012 Eitan Adler +# +# 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. +# + +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 |