ssh scp sftp (密钥对)

ssh [email protected]   =   ssh 192.168.1.128

[root@sky ~]# w -f
 12:57:14 up 15 min,  2 users,  load average: 0.00, 0.09, 0.16
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1      12:44   15:03   3.89s  3.89s /usr/bin/Xorg :0 -br -verbose -audit 4 -auth /var/run/gdm/auth-f
root     pts/1     12:47    0.00s  0.14s  0.01s w -f
[root@sky ~]# w -f
 12:57:31 up 15 min,  3 users,  load average: 0.00, 0.08, 0.16
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1      12:44   15:20   3.89s  3.89s /usr/bin/Xorg :0 -br -verbose -audit 4 -auth /var/run/gdm/auth-f
root     pts/1     12:47    0.00s  0.27s  0.13s w -f
server   pts/0     12:57    4.00s  0.01s  0.01s -bash
[root@sky ~]#

rm know-host   (在对端IP变化之后不能正常登陆)
[root@sky .ssh]# ll
总用量 0
[root@sky .ssh]# ssh server@192.168.1.151
The authenticity of host '192.168.1.151 (192.168.1.151)' can't be established.
RSA key fingerprint is b4:7a:6e:c0:0c:40:b2:82:ec:9d:c8:d9:b3:c4:9e:d1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.151' (RSA) to the list of known hosts.
server@192.168.1.151's password:
Last login: Sat Nov 28 12:57:27 2015 from 192.168.1.128
[server@sky ~]$ w -f
 13:07:19 up 25 min,  3 users,  load average: 0.00, 0.00, 0.07
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1      12:44   25:08   4.74s  4.74s /usr/bin/Xorg :0 -br -verbose -audit 4 -auth /var/run/gdm/auth-
root     pts/1     12:47    1:15   0.19s  0.19s -bash
server   pts/0     13:07    0.00s  0.16s  0.13s w -f
[server@sky ~]$ exit
logout
Connection to 192.168.1.151 closed.
[root@sky .ssh]# ll
总用量 4
-rw-r--r--. 1 root root 395 11月 28 13:07 known_hosts
[root@sky .ssh]# cat known_hosts
192.168.1.151 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArinKVqGOyc7I13M2dGgs9X3rBtKdYxj+zvn5O6fWWzhy4jggK3J+1TtW/w7NpVqlO27jtFQ91wFUg2EdL4IFL9Q/bRJld5YfRuvoGC4XKTYce8PB3KzQdbm8cd8/nfFtFumEw3GTSlJOVO6USSobgLBAXIkgUtVdeqiLqc0GRQ8Ayr0EqE8CQEQmZYJ9CGDrqGuAmLEKr2iqDhl3FDBn+mHgWkgNYGJHgTomlRRUIFIUO28NxHmHROtOnFK5bC4wBJVlYq24Q+Zz6RpaZfxXPt/WrS0r3/X2gIClAE53NDF+yqE4L0Im/WoNYpCkUlOSHaSWsbWhqobINY29e8bqmw==
[root@sky .ssh]#

 

ssh免密码登陆。配置ssh密钥对认证    公钥、私钥

1  ssh-keygen
    2  cd /home/client/.ssh/
    3  ll
    4  ssh-copy-id server@192.168.1.151
    5  ll
    6  cat id_rsa.pub
    7  cat /etc/ssh/sshd_config
    8  su -
    9  ssh server@192.168.1.151
   

[client@sky root]$ ssh [email protected]
Last login: Sat Nov 28 13:25:10 2015 from 192.168.1.128
[server@sky ~]$ cd .ssh/
[server@sky .ssh]$ ls
authorized_keys
[server@sky .ssh]$ cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqAzg/wPCEPdP1N9IyosfXWIz9hOXRP87AHZPRUTIHDdsmsfgghcfuPYLTqFS6cAdrj9zgeOzUVmCideFa1LYFLyzXldLduODIfROtwIPmK0WMwlTeBsfu8RABPJH6jvJCkfIlhgxfEmr4ZvTwAXejckH5RUYCI4+adYz3593UgYlCkf3bqQPXxn9mKZv2N0dWzcvQddNiHly3i1EUsjwa6Kql/ky3l5ISQJyaU9CKeBPez23CpE1gTBE8s9Ju/dFwg+v5vjc1TdwNMl4X8bbuqoTiKioroIiTKzortLk2tA7gEtfXclIrwahIKLiKaWAtVUpgZYsIR7og+UP3cYUn [email protected]
[server@sky .ssh]$

 

[root@sky ~]# cat /etc/ssh/sshd_config | grep Pass
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes
#KerberosOrLocalPasswd yes
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication, then enable this but set PasswordAuthentication
[root@sky ~]# cat /etc/ssh/sshd_config | grep Pub
#PubkeyAuthentication yes
[root@sky ~]#


 

[client@sky ~]$ touch {1..3}.txt
[client@sky ~]$ ll
总用量 0
-rw-rw-r--. 1 client client 0 11月 28 13:31 1.txt
-rw-rw-r--. 1 client client 0 11月 28 13:31 2.txt
-rw-rw-r--. 1 client client 0 11月 28 13:31 3.txt
[client@sky ~]$
[client@sky ~]$
[client@sky ~]$ scp *.txt server@192.168.1.151:~/
1.txt                                                                          100%    0     0.0KB/s   00:00
2.txt                                                                          100%    0     0.0KB/s   00:00
3.txt                                                                          100%    0     0.0KB/s   00:00
[client@sky ~]$ scp  server@192.168.1.151:~/A* ./
Aa.txt                                                                         100%    0     0.0KB/s   00:00
Ab.txt                                                                         100%    0     0.0KB/s   00:00
Ac.txt                                                                         100%    0     0.0KB/s   00:00
[client@sky ~]$ ll
总用量 0
-rw-rw-r--. 1 client client 0 11月 28 13:31 1.txt
-rw-rw-r--. 1 client client 0 11月 28 13:31 2.txt
-rw-rw-r--. 1 client client 0 11月 28 13:31 3.txt
-rw-rw-r--. 1 client client 0 11月 28 13:35 Aa.txt
-rw-rw-r--. 1 client client 0 11月 28 13:35 Ab.txt
-rw-rw-r--. 1 client client 0 11月 28 13:35 Ac.txt
[client@sky ~]$

 

[client@sky ~]$ sftp  server@192.168.1.151
Connected to 192.168.1.151.
sftp> pwd
Remote working directory: /home/server
sftp> lpwd
Local working directory: /home/client
sftp> ls
1.txt   2.txt   3.txt   Aa.txt  Ab.txt  Ac.txt  Z1.txt  Z2.txt  Z3.txt
sftp> get Z
Z1.txt  Z2.txt  Z3.txt
sftp> get Z*
Fetching /home/server/Z1.txt to Z1.txt
Fetching /home/server/Z2.txt to Z2.txt
Fetching /home/server/Z3.txt to Z3.txt

转载于:https://www.cnblogs.com/skyfly0772/p/5003505.html

你可能感兴趣的:(ssh scp sftp (密钥对))