linux打开63322端口,ssh、scp、ssh 免密码登陆

ssh 远程登录

ssh 命令。如果端口号是 22,则不需要指定 ssh -p 端口号 用户名@远程主机

ssh -p 51122 centosone@localhost

复制代码

在 .zshrc 中添加别名来简化命令 alias ubuntuone="ssh ubuntuone@localhost -p 61122"

alias ubuntutwo="ssh ubuntutwo@localhost -p 62222"

alias ubuntuthree="ssh ubuntuthree@localhost -p 63322"

alias centosone="ssh centosone@localhost -p 51122"

alias centostwo="ssh centostwo@localhost -p 52222"

alias centosthree="ssh centosthree@localhost -p 53322"

复制代码

scp 远程上传下载文件

1.从服务器上的下载 Hello.txt 文件到本地 test 目录,默认端口是 22,如果默认端口不是 22 的话需要用大写的 -P 来指定端口 ➜ ~ pwd

/home/centosone

➜ ~ ls

Hello.txt

➜ ~ exit

Connection to localhost closed.

➜ Docker scp -P 51122 centosone@localhost:/home/centosone/Hello.txt /Users/bingoogol/Desktop/Docker/test/

centosone@localhost's password:

Hello.txt 100% 6 0.0KB/s 00:00

➜ Docker ls test

Hello.txt

复制代码

2.上传本地的 Hello.txt 文件到服务器上,默认端口是 22,如果默认端口不是 22 的话需要用大写的 -P 来指定端口 ➜ Docker scp -P 51122 ./test/Hello.txt centosone@localhost:/home/centosone/

centosone@localhost's password:

Hello.txt 100% 12 0.0KB/s 00:00

➜ Docker ssh -p 51122 centosone@localhost

centosone@localhost's password:

Last login: Tue Jan 17 11:32:03 2017 from 192.168.56.101

➜ ~ pwd

/home/centosone

➜ ~ ls

Hello.txt

复制代码

3.从服务器下载整个 test(包含test目录本身) 目录到本地的 download 目录中,和下载单文件不同的是需要加上 -r 参数,默认端口是 22,如果默认端口不是 22 的话需要用大写的 -P 来指定端口 ➜ ~ pwd

/home/centosone

➜ ~ ls

test

➜ ~ ls test

Hello.txt test2 World.txt

➜ ~ ls test/test2

Hello.txt

➜ ~ exit

Connection to localhost closed.

➜ Docker scp -r -P 51122 centosone@localhost:/home/centosone/test /Users/bingoogol/Desktop/Docker/download

centosone@localhost's password:

Hello.txt 100% 12 0.0KB/s 00:00

World.txt 100% 6 0.0KB/s 00:00

Hello.txt 100% 12 0.0KB/s 00:00

➜ Docker ls download

test

➜ Docker ls download/test

Hello.txt World.txt test2

➜ Docker ls download/test/test2

Hello.txt

复制代码

4.上传本地 test(包含test目录本身) 目录到服务器的 /home/centosone 目录中,和上传单文件不同的是需要加上 -r 参数,默认端口是 22,如果默认端口不是 22 的话需要用大写的 -P 来指定端口 ➜ Docker ls

CentOS-7-x86_64-Minimal-1611.iso test ubuntu-16.04-server-amd64.iso

Docker镜像和容器.md ubuntu-16.04-desktop-amd64.iso

➜ Docker scp -r -P 51122 /Users/bingoogol/Desktop/Docker/test centosone@localhost:/home/centosone

centosone@localhost's password:

Hello.txt 100% 12 0.0KB/s 00:00

Hello.txt 100% 12 0.0KB/s 00:00

World.txt 100% 6 0.0KB/s 00:00

➜ Docker ssh -p 51122 centosone@localhost

centosone@localhost's password:

Last login: Tue Jan 17 12:58:32 2017 from gateway

➜ ~ ls

test

➜ ~ ls test

Hello.txt test2 World.txt

➜ ~ ls test/test2

Hello.txt

复制代码

上传 SSH 公钥上传到 Linux 服务器实现面密码登陆

1.生成 SSH 密钥和公钥 ssh-keygen -b 4096 -t rsa

复制代码

2.将公钥内容添加到服务器的 ~/.ssh/authorized_keys 文件中。

a.我这里是直接通过 scp 拷贝的(确保服务器上已经有 .ssh 目录了,没有的话需要先登陆上去创建,CentOS 需将该目录权限设置为 700) scp -P 63322 ~/.ssh/id_rsa.pub ubuntuthree@localhost:~/.ssh/authorized_keys

复制代码

b.如果服务器上之前已经有 authorized_keys 文件了 开发机

scp -P 63322 ~/.ssh/id_rsa.pub ubuntuthree@localhost:~/.ssh/new_authorized_keys

登陆到服务器上

cat ~/.ssh/new_authorized_keys >> ~/.ssh/authorized_keys

复制代码

c.如果开发机是 Linux,可以直接使用 ssh-copy-id 命令来完成公钥的上传 ssh-copy-id -i ~/.ssh/id_rsa.pub centosone@192.168.56.221

复制代码

3.如果是 CentOS 的话,还需要修改 .ssh 目录权限为 700 chmod 700 ~/.ssh

复制代码

4.如果是 CentOS 的话,可能需要重启 SSH 服务 systemctl restart sshd.service

复制代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值