how can I ssh to a linux box and copy the key to the destination in one command ??

how can I ssh to a linux box and copy the key to the destination in one command

someone showed me this once it is l or ssh-L or somelike that
LVL 1
NAMEWITHELD12Asked:
Who is Participating?
 
Murugesan NagarajanSubject-matter expert at C++ C delivery, implementation, at UNIX oriented operating systems (Windows: CYGWIN_NT MINGW32_NT MINGW64_NT)Commented:
@Scott Silva
Thank you for related answer.

@NAMEWITHELD12
1. Better use full path for /usr/bin/ssh-copy-id
In my system /bin/grep and /usr/bin/ssh-copy-id are available.
$ alias ssh-copy-id='echo Use full path /usr/bin/ssh-copy-id;echo error | /bin/grep ERROR'
$ ssh-copy-id
Use full path for ssh-copy-id
$ echo $?
1
$

Open in new window

2. before using /usr/bin/ssh-copy-id verify destination if reachable using /bin/ping
Example:
/bin/ping -c 1 localhost >/dev/null 2>&1;PingRet=$?;if [[ 0 -eq $PingRet ]];then echo you can use /usr/bin/ssh-copy-id;fi

Open in new window

0
 
Scott SilvaNetwork AdministratorCommented:
You need to use the ssh-copy-id script that uses ssh to log into a remote machine using a login password. The syntax is as follows:

ssh-copy-id user@server.example.com

OR

ssh-copy-id -i ~/.ssh/id_rsa.pub user@server.example.com
OR

ssh-copy-id -i ~/.ssh/id_dsa.pub user@sserver.example.com

OR use specific port on remote host such as tcp port # 4242:

ssh-copy-id -i /path/key/file.pub "user@server.example.com -p 4242"
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.