SSH and SCP Daily Work Summary

This article used to walk you through some commonly ssh and scp usages, based on a real life scenario.

################################################################
#   Insert latest update at the top of the logs
#
#   Date           Description
#   02/21/2019     scp folder or files
#   01/23/2019     sshpass
#   01/22/2019     no prompt first time
#   01/08/2019     ECDSA host key changed
#   01/06/2019     ssh-kenscan
#   12/19/2018     ssh-copy-id
#   11/14/2018     ssh run shell script
#   10/01/2018     ssh send command
################################################################

10/01/2018

use ssh send commands to execute on remote machine:

-t flag allow you to interact with remote machine:

11/14/2018

use ssh run shell script in remote machine

12/19/2018

use ssh-copy-id to copy local machine public key to remote machine’s ~/.ssh/authorized_keys file, so next time when you ssh again, no prompt to require password:

01/06/2019

use ssh-keyscan to get remote machine ecdsa identity, you can put this item into local known_hosts file, so when first time ssh login, there is no prompt to input yes:

actually better to use -o StrictHostKeyChecking=no flag.

01/08/2019

I create a new cluster with the same master hostname as the deleted one, so when I try to ssh to it, interesting thing happens:

go to ~/.ssh/known_hosts file and delete the corresponding ECDSA line

01/22/2019

when you first time ssh or scp to remote machine, it will prompt to add remote machine to ~/.ssh/known_hosts file, this may interrupt ansible or shell script running, so I want to skip it. For example:

use -o StrictHostKeyChecking=no option, it will silently add remote host name to ~/.ssh/known_host file.

ssh-copy-id -i .ssh/id_dsa.pub -o StrictHostKeyChecking=no [email protected]
scp -o StrictHostKeyChecking=no -r ./source [email protected]:~

if you don't want to add the host name, -o UserKnownHostsFile=/dev/null option can save you.

01/23/2019

scp or ssh without prompt input password

yum install -y sshpass
sshpass -p <password> scp/ssh ...

02/21/2019

scp source directory and it's content recursively to root directory in example.com

scp -o StrictHostKeyChecking=no -r ~/source [email protected]:~

scp all files in source directory to target directory in example.com

scp -o StrictHostKeyChecking=no ./source/* [email protected]:~/target

猜你喜欢

转载自www.cnblogs.com/chengdol/p/10434925.html