Linux Networking: SSH and SCP
Posted on June 1, 2024 (Last modified on June 8, 2024) • 2 min read • 280 wordsMaster SSH and SCP commands in Linux for secure remote access and file transfers, including key-based authentication and managing SSH sessions.
SSH and SCP are essential tools for secure remote access and file transfers in Linux. This guide covers SSH configuration, key-based authentication, and using SCP for file transfers.
Install the OpenSSH server.
sudo apt-get install openssh-server
Start and enable the SSH service.
sudo systemctl start ssh
sudo systemctl enable ssh
Edit the SSH configuration file.
sudo vim /etc/ssh/sshd_config
Restart the SSH service to apply changes.
sudo systemctl restart ssh
Generate a new SSH key pair.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Use ssh-copy-id
to copy your public key to the remote server.
ssh-copy-id user@remote_server
Connect to the remote server using key-based authentication.
ssh user@remote_server
Use tmux
to manage SSH sessions.
tmux new -s session_name
Detach from the session.
Ctrl-b d
Reattach to the session.
tmux attach -t session_name
Use screen
to manage SSH sessions.
screen -S session_name
Detach from the session.
Ctrl-a d
Reattach to the session.
screen -r session_name
Use scp
to copy files between local and remote systems.
scp local_file user@remote_server:/path/to/destination
Use -r
option to transfer directories.
scp -r local_directory user@remote_server:/path/to/destination
Use scp
to transfer files between two remote systems.
scp user1@remote1:/path/to/file user2@remote2:/path/to/destination
Mastering SSH and SCP commands is essential for secure remote access and file transfers in Linux. Practice configuring SSH, setting up key-based authentication, and using SCP for file transfers to enhance your networking skills.