欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Linux SSH连接

程序员文章站 2024-02-27 17:11:27
...

一、自带ssh通过密码连接主机

ssh [email protected] -p52113 #通过52113端口,连接这个主机的root用户

在ssh中传文件

(需要在ubuntu的/etc/ssh/sshd_config下配置:

Port 52113
PermitRootLogin yes

然后重启服务:

service sshd restart


scp -rp -P52113 hello.c [email protected]:/home/dawson/
注:
这里是把centos下的hello.c文件传到ubuntu下

二、SSH**连接(设置好**,连接时不用密码,这两个主机间就能够连接)

这里测试centos通过**连接ubuntu:

1.在centos下

在root用户下输入:ssh-******,然后回车就会输出:

Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.

/root/.ssh/id_rsa下就存放了私钥,/root/.ssh/id_rsa.pub下存放公钥

2.在ubuntu下

把centos里的公钥存入你要连接的目录下,比如一个dawson用户(/home/dawson),然后把id_rsa.pub文件内容拷到/home/dawson/.ssh/authorized_keys里(如果没有.ssh文件就自己创建,权限最好是700,即自己什么都能干,其他人什么都干不了),要注意的是公钥是完整的一行,如果因为复制时多出换行符,记得删了

3.在centos下

前面是通过root生成的**,所以在root下输入:
ssh [email protected] -p52113
就会发现连接上dawson了,并且过程当中不需要密码,所以以后如果centos的root用户想连接哪个主机只要把公钥放在该主机下就行了