近期过闲,就想着复习一下linux。复习当然是实际项目更方便嘛,就在 阿里云上买了服务器,开始了吐血之旅。
本来原来是想通过老办法即xftp以及xshell来处理。但是最开始是只能密钥连接,一想一百度行吧,配置问题然后开始用阿里云的远程控制来做。这一看脑袋都疼了啊,使用第一个登陆提示可能root登陆有问题,于是换到第二个。登陆后输入命令:
vim /etc/ssh/sshd_config
编辑配置文件:
# default value.
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
Port 22 #端口限制
#AddressFamily any
#ListenAddress 0.0.0.0 #IP限制
#ListenAddress ::
#钥配置
HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#日志等级
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#是否允许使用root登陆
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#是否用密码登陆
PasswordAuthentication yes
challengeResponseAuthentication no
#是否使用公钥登陆
PubkeyAuthentication yes
#The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
命令tip:编辑进入insert状态后,按esc返回。然后按(Shift+:)进入输入命令行,根据自己需要发送命令(保存并退出wq;退出q。如果遇见
E45: 'readonly' option is set (add ! to override)
的错误,可用wq!或q!强退(在root用户下))。
设置好之后去连接xshell很好,现在有多余选项了,但是我还是连接失败。一脸懵逼的我再次进行百度。百度部分答案是说没有开启安全设置组,于是我去了阿里云的安全设置组:
阿里有一个默认配置的安全组,如有需要自己加。
加完了以后我接着去看xshell是否能连上。遗憾的是,我又失败了。再一次百度后我又获取到了部分方法——看ssh服务是否在运行。命令:
service sshd start //启动服务
终于弹出错误:(我的忘了截图,是找的其他人的图)。根据这个错误我们输入命令:
systemctl status sshd.service
根据各种百度得到以下办法:
第一步:查看端口
semanage port -l | grep ssh
我的是找不到该接口(无截图)错误是:-bash: ssh: command not found
我惊呆了,因为一般来说阿里云服务器是会有配置的,于是输入命令查看到底在哪里
rpm -qa | grep openssh
查出来ssh又是全的,陷入深思。接着我意识到了我配置文件仿佛忘了把接口放出来。再次用上面提到的修改配置文件去看,果不其然,端口配置被灰了。改动后成功连接。可以进行下一步了。
//添加一个名为test的用户
#passwd test//修改密码
Changing password for user test.
New UNIX password: //在这里输入新密码
Retype new UNIX password: //再次输入新密码
passwd: all authentication tokens updated successfully.
建完新用户,就要将root的权限分配给他,输入命令:
vim /etc/sudoers
编辑权限配置文件:找到该注释行,并且在root下面添加需要权限的用户
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
test ALL=(ALL) ALL