阿里云ECS,配置ssh远程登录

一.root用户登录远程linux服务器

1.更改ssh默认端口

vim /etc/ssh/sshd_config

Port 自定义端口号

PermitRootLogin yes 允许root登录

PubkeyAuthentication yes 允许公匙认证

PasswordAuthentication yes 允许密码认证

PermitEnptyPassword no 禁止空密码登录

/etc/init.d/ssh restart 重启ssh服务

2.将本机ssh密匙上传至服务器

ssh-copy-id -i id_rsa.pub -p 1121 root@47.106.191.56

3.客户端使用ssh连接ecs服务器,在~/.ssh目录下新建config文件并添加一下代码

Host ali
  HostName <rempteIp>
  Port <remotePort>
  User root
LocalForward <localPort> <remoteIp>:<remotePort>
IdentityFile ~/.ssh/id_rsa

4.打开git bash登录远程服务器

成功登录远程服务器

二.远程服务器新建用户,并使用此账户ssh连接远程服务器

1.新建用户 xxx

adduser xxx   添加用户

cat /etc/shadow 查看当前系统所有用户

2.客户端生成ssh密匙

ssh-keygen -t rsa -C "xxx" -f "xxx"   #ssh生成密匙其他方法请自行百度 

3.将密匙上传至服务器

scp -P 1121 name.pub root@47.106.191.56: #上传到远程服务器的目录root目录下

4.在刚刚添加用户的主目录下新建.ssh文件夹并添加authorized_keys文件

mkdir /home/erp/.ssh

touch /home/erp/.ssh/authorized_keys

chgrp -R erp .ssh #将.ssh目录及目录下所有文件所属组更改为erp

chown -R erp .ssh #将.ssh目录及目录下所有文件所属用户更改为erp
chmod 700 .ssh    #更改.ssh目录的权限

chmod 600 .ssh/authorized_keys #更改authorized_keys的权限
cat /root/erp.pub > /home/erp/.ssh/authorized_keys #将刚刚上传的公匙添加到authorized_keys

5.客户机使用新建用户登录远程服务器

Host ali
  HostName <rempteIp>
  Port <remotePort>
  User erp
LocalForward <localPort> <remoteIp>:<remotePort>
IdentityFile ~/.ssh/id_rsa

6.使用git bash登录

ssh ali

 

posted @ 2018-11-02 21:52  czy21  阅读(18597)  评论(0编辑  收藏  举报