This article used to walk you through some commonly ssh
and scp
usages, based on a real life scenario.
################################################################
# 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 root@example.com "cd /home/demo; ls -ltr"
-t
flag allow you to interact with remote machine:
ssh -t root@example.com "top"
11/14/2018
use ssh run shell script in remote machine
ssh root@example.com < 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 root@example.com
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 root@example.com
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 root@example.com
scp -o StrictHostKeyChecking=no -r ./source root@example.com:~
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 root@example.com:~
scp all files in source
directory to target
directory in example.com
scp -o StrictHostKeyChecking=no ./source/* root@example.com:~/target
网友评论