Linux远程连接&文件传输
SSH协议
- SSH是一种网络协议,用于计算机之间的加密登录。用户可以从本地计算机,使用SSH协议远程登录另一台计算机。
sshd服务
端口号可以让计算机区分出不同的服务
常用远程连接软件(了解)
Putty
PuTTY为一开放源代码软件,小巧轻便,但功能单一
SecureCRT
SecureCRT是一款支持SSH(SSH1和SSH2)的终端仿真程序,缺点是颜色方案不符合大众习惯
XShell
Xshell是一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Windows 平台的TELNET 协议。Xshell 通过互联网到远程主机的安全连接以及它创新性的设计和特色帮助用户在复杂的网络环境中享受他们的工作。缺点:收费
SSH远程连接
口令连接
获取自己的ip
[root@server1 ~]
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:76:f9:7d brd ff:ff:ff:ff:ff:ff
inet 192.168.226.10/24 brd 192.168.226.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::1b78:bfb3:4567:b45c/64 scope link noprefixroute
valid_lft forever preferred_lft forever
ip地址为192.168.226.10
$ ssh root@192.168.226.10
输入设置的密码即可登录
公钥连接(免密登录)
- 需要在本地生成密钥对,然后把密钥对中的公钥上传至服务器,并与服务器中的公钥进行比较;该方式相较来说更安全。
客户端主机中生成“密钥对”
[root@client ~]
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
SHA256:olnJ6qKrHOywFyCOr3elrSjJewf+Tbwn4CG1zNJS1+8 root@client
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| . |
|o + o . |
|+. * B S . |
|o..= %o. . |
|o=..X+oo . |
|*o*=oo+... E |
|B@+o=o oo |
+----[SHA256]-----+
[root@client ~]# ls /root/.ssh/
id_rsa id_rsa.pub
id_rsa私钥文件
id_rsa.pub公钥文件
将客户端主机中生成的公钥文件传送至远程主机
[root@client ~]# ssh-copy-id root@192.168.226.20
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.226.20 (192.168.226.20)' can't be established.
ECDSA key fingerprint is SHA256:+RvxL8ZDWnyO030Z5rOfjBuJaOG1yFvD9ieOY9uzWBA.
ECDSA key fingerprint is MD5:d2:a2:8c:c6:60:15:46:9b:09:75:ce:3f:e1:ea:6e:aa.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.226.20's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.226.20'"
and check to make sure that only the key(s) you wanted were added.
[root@server ~]
authorized_keys <--客户端发来的公钥文件
也可以先在远程主机上创建/root/.ssh/authorized_keys文件,然后把客户端公钥文件里面的内容复制到该文件内
文件传输
scp 远程拷贝文件
- 主机之间复制文件必需得同时有两台主机的复制执行帐号和操作权限。
[root@client ~]
test1 100% 0 0.0KB/s 00:00
[root@server ~]
ks-script-MRke4N test1 yum.log
lrzsz Windows与Linux互传文件
yum install lrzsz -y
rz
选择文件,存到Linux
sz test1
选择存放位置,可存到Windows中
|