Linux命令:ssh,scp使用及免密码登录

一、ssh使用:


ssh  [email protected]

ssh  -l  USERNAME HOST

ssh  [email protected] ‘COMMAND‘  单引号

[[email protected] ~]# ssh 110.119.131.204 #第一次连接需发送主机认证

Theauthenticity of host ‘110.119.131.204 (110.119.131.204)‘ can‘t be established.

RSAkey fingerprint is 91:a3:75:4b:3c:50:fd:5a:60:1a:39:ab:d5:0b:83:16.

Areyou sure you want to continue connecting (yes/no)? y

[[email protected]]# cat known_hosts

110.119.131.195ssh-rsaAAAAB3NzaC1yc2EAAAABIwAAAQEA7WecSyXB82qLwTOmh/Mhh8ic80Oj/lhS2xTjVHLz5jy8aq6XxS8gOVErcJZU4qL/eG0aDEMiyUQ5OChq1IUu3U+dO0eHLgpCt6UMd/LAxYjB5rvXE6pCvESJpTRK/oJEhnnzjHXLxZG2tD8t2xy1Bvt8+6K+2TBX64z2uEav8Yy5DcH2zQzMP/4bkn7my0WPDlwRsFSDW2CE/0GWFqKL8PWt2r9DoUS4c5umwqPe4cqyvvLA960YmeNuMlnNBKp2XOBrTpLsigsIXO6lVqhEcWUU1bV7JRPmgQbZjCu5onw1Ez4929XkVroxX02E9IS6DBGN6U6tMIC8fMwUjjrbXQ==

二、scp使用:


scpSRC DEST      -r递归        -a

[email protected]:/path/to/somefile /path/to/local

scp/path/to/local [email protected]:/path/to/somewhere

[[email protected] ~]# scp 10.109.131.204:/etc/fstab ./
[email protected]‘s password:
Permission denied, please try again.
[email protected]‘s password:
fstab                                                                 100%  854     0.8KB/s   00:00    
[[email protected] ~]# ls
anaconda-ks.cfg  Desktop      install.log.syslog  minsysbak   rc.sysreboot
bincopy.sh       fstab        mbox                rc.reboot   test
cpbin.sh         install.log  minitest            rc.sysdone  testiso
[[email protected] ~]# ll fstab
-rw-r--r-- 1 root root 854 Dec  5 16:53 fstab
[[email protected] ~]# date
Mon Dec  5 16:53:28 CST 2016

ssh-keygen

-trsa

~/.ssh/id_rsa

~/.ssh/id_rsa.pub

-f /path/to/KEY_FILE

-P ‘‘: 指定加密私钥的密码

三、自动保存登录密码:

多命令实现自动保存登录密码:

[[email protected] ~]# ssh -keygen -t rsa
Bad escape character ‘ygen‘.
[[email protected] ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
d8:f0:bb:be:4b:aa:c0:59:4d:55:de:77:13:36:d7:11 [email protected]
[[email protected] ~]# ls .ssh/
id_rsa  id_rsa.pub  known_hosts
[[email protected] ~]# scp .ssh/id_rsa.pub [email protected]:/root
[email protected]‘s password:
Permission denied, please try again.
[email protected]‘s password:
id_rsa.pub                                                            100%  391     0.4KB/s   00:00    
[[email protected] ~]# ssh 10.109.131.204
[email protected]‘s password:
Last login: Mon Dec  5 16:18:26 2016 from 10.109.131.209

[[email protected] ~]# cat id_rsa.pub >> .ssh/authorized_keys
[[email protected] ~]# exit
logout
Connection to 10.109.131.204 closed.
[[email protected] ~]# ssh 10.109.131.204  #无密码进入
Last login: Mon Dec  5 17:09:57 2016 from 10.109.131.209

单命令实现自动保存登录密码:

[[email protected] ~]# ssh-keygen -t rsa -f .ssh/id_rsa -P ‘‘
Generating public/private rsa key pair.

Your identification has been saved in .ssh/id_rsa.
Your public key has been saved in .ssh/id_rsa.pub.
The key fingerprint is:
f8:b2:7d:64:20:ec:5f:09:3f:3f:2b:96:df:33:60:d3 [email protected]

[[email protected] ~]# ssh 10.109.131.204
Last login: Mon Dec  5 17:11:14 2016 from 10.109.131.209
[[email protected] ~]# ssh-copy-id  -i  ~/.ssh/id_rsa.pub [email protected]
[email protected]‘s password:
Now try logging into the machine, with "ssh ‘[email protected]‘", and check in:
  .ssh/authorized_keys
to make sure we haven‘t added extra keys that you weren‘t expecting.

[[email protected] ~]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:57583               0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 :::111                      :::*                        LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      
tcp        0      0 :::45668                    :::*                        LISTEN

---end---

时间: 2024-08-01 10:30:58

Linux命令:ssh,scp使用及免密码登录的相关文章

详解ssh通过公钥密码、免密码登录以及导入公钥文件三种形式实现远程登录

简介 SSH(Secure Shell)是一种安全通道协议,主要用来实现字符界面的远程登录.远程复制等功能,SSH协议对通信双方的数据传输进行了加密处理,其中包括用户登录时输入的用户口令,与TELNET(远程登录,明文传递)等应用相比,SSH协议提供了更好的安全性 对称加密算法 采用单钥密码系统的加密方法,同一个密钥可以同时用作信息的加密和解密,这种加密方法称为对称加密,也称为单密钥加密.加密和解密是一样的,例如密码123,都是明文,用户密码并不多,有可能其他数据密码也用这个密码,一旦截获,直接

ssh使用秘钥免密码登录

使用ssh远程连接服务器,有两种身份校验方式:账号密码和秘钥.使用秘钥的方式理论上更加安全,而且免去了输入密码的步骤,使用起来更方便(尤其对于sftp,scp等). ssh秘钥的生成和使用,网上很多教程,感觉不太完整,这里自己总结一下. 秘钥由谁生成这是比较容易搞乱的一点.这里以A.B两台服务器为例,假设A需要ssh登录B,那么应该由那台服务器生成秘钥呢.可能有人以为像门锁一样,主人家负责装锁配钥匙,把钥匙交给要开门的人使用,所以由被访问的B服务器生成秘钥. 事实恰恰相反,秘钥由访问请求方A服务

配置免密码登录

.配置免密码登录 免密码登录可以在任意一台机器上输入命令,可以启动所有机器上的进程 如果不做免密码登录,需要在每一台机器上输入启动进程命令 配置201上的免密码登录 在201上生成秘钥 ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa 在.ssh目录下生成 [[email protected] .ssh]# ls authorized_keys id_dsa id_dsa.pub known_hosts [[email protected] .ssh]# id_d

ssh-keygen生成公私钥免密码登录远程服务器

经常需要登录远程服务器很麻烦,因此在此记录下免密码登录远程服务器的那些事. 1. 比较常用而保险的ssh-keygen公私钥配对登录. 2. 终端输入命令:ssh-keygen -t rsa 这里需要你输入一个钥匙的名称,不输入默认为:id_rsa (私钥) 和 id_rsa.pub(公钥) 通常在企业里面一台服务器有很多人使用,因此默认的名称很可能已经有人使用了,所以这里可以输入一个你自己的名字为好. 3. 输入密钥名称后,回车,会让输入密码. 4. 因为我们要免密码登录,所以别填,直接回车2

Linux使用ssh公钥实现免密码登录Linux

ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例. 有机器A(192.168.1.155),B(192.168.1.181).现想A通过ssh免密码登录到B.首先以root账户登陆为例. 1.在A机下生成公钥/私钥对. [[email protected] ~]# ssh-keygen -t rsa -P '' -P表示密码,-P '' 就表示空密码,也可以不用-P参数,这样就要三车回车,用-P就一次回车.该命令将在/root

linux操作系统-两台linux服务器SSH免密码登录

A为本地主机(即用于控制其他主机的机器) ; B为远程主机(即被控制的机器Server), ip为192.168.100.247 ; A和B的系统都是Linux 在A上的命令 # ssh-keygen -t rsa (连续三次回车,即在本地生成了公钥和私钥,不设置密码) # ssh [email protected]192.168.100.247 "mkdir .ssh;chmod 0700 .ssh" (需要输入密码, 注:必须将.ssh的权限设为700) # scp ~/.ssh/

CentOS6.9下ssh密钥登录配置步骤(免密码登录)和ssh-keygen 命令常用参数

密钥登录步骤(免密码登录)ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,出于安全方面的考虑,介绍密钥认证方式登录到linux/unix的方法. 使用密钥登录分为3步: 1.生成密钥(公钥与私钥): 2.放置公钥到服务器~/.ssh/authorized_key文件中: 3.配置ssh客户端使用密钥登录.--------------------- 一.通过ssh-keygen命令生成密钥对,密钥类型为RSA,也可以通过其他软件生产密钥对

Debian9.5下ssh密钥登录配置步骤(免密码登录)和ssh-keygen 命令常用参数

密钥登录步骤(免密码登录)ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,出于安全方面的考虑,介绍密钥认证方式登录到linux/unix的方法. 使用密钥登录分为3步: 1.生成密钥(公钥与私钥): 2.放置公钥到服务器~/.ssh/authorized_key文件中: 3.配置ssh客户端使用密钥登录.--------------------- 一.通过ssh-keygen命令生成密钥对,密钥类型为RSA,也可以通过其他软件生产密钥对

Linux SSH 免密码登录

工作中经常要登录的Linux主机太多,每次输密码太麻烦,配过几次免密码登录,每次都记不住,这次记下来备忘. 首先在自己机器上使用 ssh-keygen 工具来创建密钥,如下 ssh-keygen -t rsa 使用 ssh-copy-id 命令自动在目标服务器上生成~/.ssh/authorized_keys文件 ssh-copy-id -i ~/.ssh/id_rsa.pub <目标机器> 转载请以链接形式标明本文地址 本文地址:http://blog.csdn.net/kongxx/art