openssh
程序员面试:
题目:在Linux系统中,如何设置和配置远程登录(SSH)服务?请提供相关命令和配置文件。
答案:
在Linux系统中,设置和配置远程登录(SSH)服务需要进行以下步骤:
1、安装OpenSSH服务器(如果尚未安装):
sudo?apt?install?openssh-server??#?Ubuntu/Debian
sudo?yum?install?openssh-server??#?CentOS/RHEL
2、启动SSH服务:
sudo?service?ssh?start??#?Ubuntu/Debian
sudo?systemctl?start?sshd??#?CentOS/RHEL
3、配置SSH服务器的相关选项。可以编辑SSH服务器的配置文件 /etc/ssh/sshd_config,修改其中的参数来满足您的需求。以下是一些常用的配置选项:
1)、监听特定IP地址或接口:
#?将下面的IP地址修改为您希望SSH服务器监听的地址
ListenAddress?0.0.0.0
2)、允许或禁止密码登录:
#?设置为yes允许使用密码登录,设置为no仅允许使用密钥登录
PasswordAuthentication?yes
3)、更改SSH服务器的监听端口(可选):
#?将下面的端口号修改为您希望SSH服务器监听的端口,默认是22
Port?22
4)、允许或禁止root用户远程登录(可选):
#?设置为yes允许root用户远程登录,设置为no禁止root用户远程登录
PermitRootLogin?yes
5)、允许或禁止SSH会话保持活动:
#?设置为yes启用KeepAlive,设置为no禁用KeepAlive
TCPKeepAlive?yes
4、重启SSH服务以应用配置更改:
sudo?service?ssh?restart??#?Ubuntu/Debian
sudo?systemctl?restart?sshd??#?CentOS/RHEL
现在,您应该能够通过SSH远程登录到Linux系统了。您可以使用以下命令来进行远程登录:
ssh?username@ip_address
其中,username是您在Linux系统上的用户名,ip_address是Linux系统的IP地址或主机名。
请注意,修改SSH服务器的配置文件时要谨慎,确保使用正确的参数和值,并始终备份原有配置文件以防出现问题。#程序员##面试##Linux#
openssh漏洞修复建议
安全部门扫描系统漏洞,OpenSSH 7.9出现漏洞,需升级到8。使用 rpmbuild 将源码包编译为 rpm包。
yum install rpm-build zlib-devel openssl-devel gcc perl-devel pam-devel unzip -ymkdir -p /root/rpmbuild/{SOURCES,SPECS}cd /root/rpmbuild/SOURCES wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.0p1.tar.gzwget https://src.fedoraproject.org/repo/pkgs/openssh/x11-ssh-askpass-1.2.4.1.tar.gz/8f2e41f3f7eaa8543a2440454637f3c3/x11-ssh-askpass-1.2.4.1.tar.gztar zxvf openssh-8.0p1.tar.gz openssh-8.0p1/contrib/redhat/openssh.specmv openssh-8.0p1/contrib/redhat/openssh.spec ../SPECS/chown sshd:sshd /root/rpmbuild/SPECS/openssh.speccp /root/rpmbuild/SPECS/openssh.spec /root/rpmbuild/SPECS/openssh.spec_defsed -i -e "s/%define no_gnome_askpass 0/%define no_gnome_askpass 1/g" /root/rpmbuild/SPECS/openssh.specsed -i -e "s/%define no_x11_askpass 0/%define no_x11_askpass 1/g" /root/rpmbuild/SPECS/openssh.speccd /root/rpmbuild/SPECS/rpmbuild -ba openssh.spec编译过程遇到的错误:
错误:构建依赖失败: openssl-devel < 1.1 被 openssh-8.0p1-1.el7.x86_64 需要解决:[root@localhost SPECS]# vim openssh.spec 注释掉 BuildRequires: openssl-devel < 1.1 这一行
安装后要修改选项:
cd /etc/ssh/chmod 400 ssh_host_ecdsa_key ssh_host_ed25519_key ssh_host_rsa_keyecho "PermitRootLogin no" >> /etc/ssh/sshd_configsystemctl restart sshdcentos 7 记得修改这个文件。不然会出现密码是对的,却无法登陆。
[root@iZ16pk5aqeZ ~]# cat /etc/pam.d/sshd#%PAM-1.0auth required pam_sepermit.soauth include password-authaccount required pam_nologin.soaccount include password-authpassword include password-auth## pam_selinux.so close should be the first session rulesession required pam_selinux.so closesession required pam_loginuid.so## pam_selinux.so open should only be followed by sessions to be executed in the user contextsession required pam_selinux.so open env_paramssession optional pam_keyinit.so force revokesession include password-auth
cydia安装openssh
苹果手机停用后.进入ssh通道的方法如下,
1.在Cydia中搜索、安装OpenSSH软件。
2.安装之后,打开设置 -> WiFi,点击已经连接的WiFi的右边的小箭头查看详情。
3.记下iPhone当前网络IP地址。
4.在PC端打开SSH软件,如Putty、SecureCRT等,都差不多,下面以免费的Putty举例说明如何连接。
5.下载Putty后,不需要安装,直接打开即可。
6.打开之后输入第4步中记下的网络IP地址,当然你的电脑需要与PC保持在同一个网络下才行:
7.点击Open开始进行远程连接,首先会弹出一个警告,点击Y.
8.连接上之后需要校验用户名和密码,用户名使用root,密码默认为alpine.
9.连接上之后就像操作一台普通unix系统一样,这里我们为了安全起见修改一下root密码,非常简单,但前提是需要有一点linux基础。