使用完cat /etc/ssh/sshd_config命令后怎么保存
时间: 2023-08-10 09:09:42 浏览: 77
在 Linux 中使用 "cat /etc/ssh/sshd_config" 命令是查看 sshd 配置文件的内容。如果想要保存这个文件,可以通过以下两种方法:
1. 将命令的输出重定向到一个新的文件中,例如:
```
cat /etc/ssh/sshd_config > new_sshd_config
```
这将会将 "cat /etc/ssh/sshd_config" 命令的输出保存到一个名为 "new_sshd_config" 的新文件中。
2. 直接在命令行中打开 sshd 配置文件,修改并保存:
```
sudo nano /etc/ssh/sshd_config
```
这将会使用 nano 编辑器打开 sshd 配置文件,您可以修改文件并使用 "Ctrl + X" 退出,然后输入 "Y" 保存文件。
相关问题
centos cat: /etc/ssh/sshd_config: No such file or directory
这个错误提示表明在CentOS操作系统中,/etc/ssh/sshd_config文件不存在。可能的原因是OpenSSH服务器没有安装或者已经卸载,或者是该文件被删除或者移动到了其他位置。你可以尝试安装OpenSSH服务器或者在其他目录中寻找该文件。你可以使用以下命令来安装OpenSSH服务器:
```
sudo yum install openssh-server
```
安装完成后,/etc/ssh/sshd_config文件应该会被创建。
``` getenforce#查看SELinux 安全机制 setenforce 0#将 SELinux 的执行模式从强制模式(Enforcing)切换为宽松模式(Permissive) cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/sshd.old.service sed -i -e 's/^Type=.*/Type=simple/g' -e '/ExecStart=/{s/\/usr\/sbin\/sshd/\/usr\/local\/sbin\/sshd/g}' /usr/lib/systemd/system/sshd.service#将文件中以"Type="开头的行替换为"Type=simple";包含"ExecStart="的行中,将"/usr/sbin/sshd"替换为"/usr/local/sbin/sshd" sed -i "s/GSSAPIAuthentication/#GSSAPIAuthentication/" /etc/ssh/sshd_config#将/etc/ssh/sshd_config文件中的"GSSAPIAuthentication"替换为"#GSSAPIAuthentication" sed -i "s/GSSAPICleanupCredentials/#GSSAPICleanupCredentials/" /etc/ssh/sshd_config sed -i "s/#PermitRootLogin yes/PermitRootLogin yes/" /etc/ssh/sshd_config sed -i "s/#UsePAM yes/UsePAM yes/" /etc/ssh/sshd_config chmod 600 /etc/ssh/ssh_host_rsa_key chmod 600 /etc/ssh/ssh_host_ecdsa_key chmod 600 /etc/ssh/ssh_host_ed25519_key mv /usr/local/sbin/sshd /usr/local/sbin/sshd.old202211 mv /lib64/libcrypto.so.1.1 /lib64/libcrypto.so.1.1.old202211 mv /srv/libcrypto.so.1.1 /lib64/ mv /srv/sshd /usr/local/sbin/ chmod 755 /usr/local/sbin/sshd chmod 755 /lib64/libcrypto.so.1.1 systemctl daemon-reload systemctl restart sshd.service source /etc/profile sshd -V useradd secure echo 'Ofm#6%3%fm0IWH'|passwd --stdin secure echo "secure ALL=(ALL) ALL" >> /etc/sudoers sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config service sshd restart systemctl daemon-reload systemctl restart sshd.service sed -i "s/secure ALL=(ALL) ALL/secure ALL=(ALL) NOPASSWD: ALL/" /etc/sudoers chage -M 99999 secure sleep 2 useradd aqassoc echo 'dAxgDt^7LT' | passwd --stdin aqassoc mkdir /batshell chown -R aqassoc:aqassoc /batshell echo 'aqassoc ALL=(ALL) NOPASSWD:ALL,!/bin/su,!/sbin/init,!/sbin/shutdown,!/sbin/halt,!/sbin/reboot,!/usr/sbin/visudo,!/usr/bin/passwd' >> /etc/sudoers sh /srv/script.sh sleep 2 tar -xvf /srv/ssl-1.1.1o* -C /srv/ mv /usr/bin/openssl /usr/bin/openssl.old mv /usr/include/openssl /usr/include/openssl.old cp /etc/ld.so.conf /etc/ld.so.conf.old ln -s /srv/ssl-1.1.1o/bin/openssl /usr/bin/openssl ln -s /srv/ssl-1.1.1o/include/openssl /usr/include/openssl srvlib=`cat /etc/ld.so.conf | grep '/srv/ssl-1.1.1o/lib/' | wc -l` if [ $srvlib -eq 0 ];then sed -i 's/\/srv/#\/srv/'g /etc/ld.so.conf echo '/srv/ssl-1.1.1o/lib/' >> /etc/ld.so.conf else echo 'ssl-1.1.1n is ok!' fi ldconfig -v |grep ssl openssl version rm -rf /srv/root_password.sh rm -rf /srv/ssl-1.1.1o_7.tar.gz curl --connect-timeout 10 -# http://133.64.86.246/iso/shell/initialization.sh -o /tmp/initialization.sh # 只有两个参数 dcn/dmz netbond/netskip baseline/baseskip sh /tmp/initialization.sh dcn netbond/netskip baseline/baseskip ```
这段代码看起来是一系列的命令,用于进行系统配置和安装操作。请注意,这些命令可能会对系统进行重要的更改和安装软件包,因此在运行之前,请确保你对这些操作有充分的了解,并且在适当的环境中执行。
以下是这段代码的逐行解释:
```bash
getenforce # 查看 SELinux 安全机制
setenforce 0 # 将 SELinux 的执行模式从强制模式(Enforcing)切换为宽松模式(Permissive)
# 备份 sshd.service 文件
cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/sshd.old.service
# 修改 sshd.service 文件内容
sed -i -e 's/^Type=.*/Type=simple/g' -e '/ExecStart=/{s/\/usr\/sbin\/sshd/\/usr\/local\/sbin\/sshd/g}' /usr/lib/systemd/system/sshd.service
# 修改 sshd_config 文件内容
sed -i "s/GSSAPIAuthentication/#GSSAPIAuthentication/" /etc/ssh/sshd_config
sed -i "s/GSSAPICleanupCredentials/#GSSAPICleanupCredentials/" /etc/ssh/sshd_config
sed -i "s/#PermitRootLogin yes/PermitRootLogin yes/" /etc/ssh/sshd_config
sed -i "s/#UsePAM yes/UsePAM yes/" /etc/ssh/sshd_config
# 修改文件权限
chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key
# 移动文件和更改权限
mv /usr/local/sbin/sshd /usr/local/sbin/sshd.old202211
mv /lib64/libcrypto.so.1.1 /lib64/libcrypto.so.1.1.old202211
mv /srv/libcrypto.so.1.1 /lib64/
mv /srv/sshd /usr/local/sbin/
chmod 755 /usr/local/sbin/sshd
chmod 755 /lib64/libcrypto.so.1.1
systemctl daemon-reload
systemctl restart sshd.service
source /etc/profile
sshd -V
# 创建用户 secure,并设置密码,配置 sudo 权限
useradd secure
echo 'Ofm#6%3%fm0IWH' | passwd --stdin secure
echo "secure ALL=(ALL) ALL" >> /etc/sudoers
sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config
service sshd restart
systemctl daemon-reload
systemctl restart sshd.service
sed -i "s/secure ALL=(ALL) ALL/secure ALL=(ALL) NOPASSWD: ALL/" /etc/sudoers
chage -M 99999 secure
sleep 2
# 创建用户 aqassoc,并设置密码,创建目录并设置权限,配置 sudo 权限,执行脚本
useradd aqassoc
echo 'dAxgDt^7LT' | passwd --stdin aqassoc
mkdir /batshell
chown -R aqassoc:aqassoc /batshell
echo 'aqassoc ALL=(ALL) NOPASSWD:ALL,!/bin/su,!/sbin/init,!/sbin/shutdown,!/sbin/halt,!/sbin/reboot,!/usr/sbin/visudo,!/usr/bin/passwd' >> /etc/sudoers
sh /srv/script.sh
sleep 2
# 解压 ssl-1.1.1o.tar.gz 文件,并设置软链接,配置 ld.so.conf
tar -xvf /srv/ssl-1.1.1o* -C /srv/
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/include/openssl /usr/include/openssl.old
cp /etc/ld.so.conf /etc/ld.so.conf.old
ln -s /srv/ssl-1.1.1o/bin/openssl /usr/bin/openssl
ln -s /srv/ssl-1.1.1o/include/openssl /usr/include/openssl
srvlib=`cat /etc/ld.so.conf | grep '/srv/ssl-1.1.1o/lib/' | wc -l`
if [ $srvlib -eq 0 ];then
sed -i 's/\/srv/#\/srv/'g /etc/ld.so.conf
echo '/srv/ssl-1.1.1o/lib/' >> /etc/ld.so.conf
else
echo 'ssl-1.1.1n is ok!'
fi
ldconfig -v | grep ssl
openssl version
# 清理临时文件
rm -rf /srv/root_password.sh
rm -rf /srv/ssl-1.1.1o_7.tar.gz
# 下载并执行 initialization.sh 脚本
curl --connect-timeout 10 -# http://133.64.86.246/iso/shell/initialization.sh -o /tmp/initialization.sh
# 执行 initialization.sh 脚本,传递参数
sh /tmp/initialization.sh dcn netbond/netskip baseline/baseskip
```
请确保你对这些命令的含义和可能的影响有清楚的了解,并在合适的环境中运行它们。