SSH and SCP Daily Work Summary

# This article used to record ssh and scp usage I learned in my daily work
# 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:

ssh [email protected] "cd /home/demo; ls -ltr"

-t flag allow you to interact with remote machine:

ssh -t [email protected] "top"

11/14/2018

use ssh run shell script in remote machine

ssh [email protected] < script.sh

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:

ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

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:

ssh-keyscan example.com

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, there is a POSSIBLE DNS SPOOFING DETECTED warning.
solution: 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:

ssh-copy-id [email protected]

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章