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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
@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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.